Auto Update Raspberry Pi Using a Script and Cron

Raspberry Pi Logo

Auto Update Raspberry Pi Using a Script and Cron

Create Script

nano update.sh 
#!/bin/sh
sudo apt-get update && sudo apt-get upgrade -y 
sudo rpi-update -y
sudo apt-get autoremove -y
sudo apt-get autoclean -y
sudo reboot

Adjust Permission to Allow Execution

chmod +x update.sh

Create a Log Directory

This is optional but highly recommend as all the console output will be piped into this area. Makes it very easy to troubleshoot if anything goes wrong.

mkdir logs
touch ./logs/cronlog

Set Up Cron

crontab -e
0 0 * * SAT sh /home/pi/update.sh 2>/home/pi/logs/cronlog

In order to redirect STDERR you have to specify “2>”

Inspecting Logs

cat ./logs/cronlog

Related

What is Filling Up Raspberry Pi Disk?

Enable 2FA on Raspberry Pi

Access Raspberry Pi Desktop from Ubuntu

Install WireGuard VPN on Raspberry Pi

,