Auto Update/Upgrade Raspberry Pi

Bipul Kuri
1 min readJan 17, 2019

--

There are few ways we can autoupdate raspberry-pi.Please read cron basics here for Raspberry Pi

  1. Cron based
  2. Cron based script
  3. apt module based

1) Cron based

add directly to crontab

crontab -e

add the following line via your favorite editor for a midnight update

0 0 * * *  root apt update && apt upgrade -y

2) cron based script

add directly to crontab

crontab -e

add the following line via your favorite editor for a midnight update

0 0 * * *  root /home/pi/up2date.sh

where the file /home/pi/up2date.sh is

pi@raspberrypi:~ $ ls -lrt /home/pi/up2date.sh
-rwxr-xr-x 1 pi pi 41 Jan 16 18:57 /home/pi/up2date.sh
pi@raspberrypi:~ $ cat /home/pi/up2date.sh
sudo apt-get update
sudo apt-get upgrade
pi@raspberrypi:~ $

3) apt module based

Do a install of unattended-upgrades apt module

sudo apt-get install unattended-upgrades -y

edit the config file by your editor

sudo vi /etc/apt/apt.conf.d/50unattended-upgrades

add the following lines in Unattended-Upgrade::Origins-Pattern section

Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"origin=Raspbian,codename=${distro_codename},label=Raspbian";
"origin=Raspberry Pi Foundation,codename=${distro_codename},label=Raspberry Pi Foundation";

};

verify in the log file that the origin are picked up correctly

cat /var/log/unattended-upgrades/unattended-upgrades.log

--

--