PabloS83
Posts: 9
Joined: Mon Apr 27, 2020 2:07 pm

Keepign PI4 up to date

Tue May 05, 2020 1:10 pm

In Windows, if I wanted these commands to run weekly or monthly as a script, I would save them in a .bat file and use the task scheduler to have them run when I wanted. How can I do that with my Raspberry PI4 to keep its distro and all installed packages up to date?

Code: Select all

sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt clean -y && sudo apt autoclean -y && sudo apt-get dist-upgrade

User avatar
bomblord
Posts: 266
Joined: Sun Jul 14, 2019 2:54 am

Re: Keepign PI4 up to date

Tue May 05, 2020 1:37 pm

The raspberry pi foundation has a good writeup on this. Use the linux crontab command
https://www.raspberrypi.org/documentati ... ge/cron.md

klricks
Posts: 7154
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Keepign PI4 up to date

Tue May 05, 2020 1:38 pm

cron
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

jbudd
Posts: 1409
Joined: Mon Dec 16, 2013 10:23 am

Re: Keepign PI4 up to date

Tue May 05, 2020 1:42 pm

Save them in a .bat script file and use the task scheduler cron to have them run when I wanted.

If you execute the script from root's cron sudo crontab -e you won't need all the sudos.

pcmanbob
Posts: 9462
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Keepign PI4 up to date

Tue May 05, 2020 1:44 pm

So you don't need the last command in your list, as sudo apt full-upgrade replaced it.

to do this automatically you would need to create a file containing the commands like this

Code: Select all

#!/bin/bash
apt update -y &&  apt full-upgrade -y &&  apt autoremove -y &&  apt clean -y &&  apt autoclean -y 
save it with a name like myupdate.sh and then make it executable with

Code: Select all

chmod 751 /home/pi/myupdate.sh
now to run it using cron

Code: Select all

sudo crontab -e
entering the line

Code: Select all

0 9 * * 0 /home/pi/myupdate.sh >> log.tx 2>&1
which would run it

Your cron job will be run at: (5 times displayed)

2020-05-10 09:00:00 UTC
2020-05-17 09:00:00 UTC
2020-05-24 09:00:00 UTC
2020-05-31 09:00:00 UTC
2020-06-07 09:00:00 UTC
...

this is of course if you are happy to blindly install updates without being able to choose options when there are changes to config files, which might leave you with a broken system.

you will also need to do a reboot in some instances , like new kernel installs , but as you will not know when these have taken place you may have to reboot on every update.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

W. H. Heydt
Posts: 12646
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Keepign PI4 up to date

Tue May 05, 2020 2:42 pm

Also bear in mind that a reboot is required to update the EEPROM firmware on the Pi4B. You check on that by running "sudo rpi-eeprom-update", and look at the dates of the current and latest versions.

bjtheone
Posts: 862
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Keepign PI4 up to date

Tue May 05, 2020 2:51 pm

pcmanbob wrote:
Tue May 05, 2020 1:44 pm
this is of course if you are happy to blindly install updates without being able to choose options when there are changes to config files, which might leave you with a broken system.

you will also need to do a reboot in some instances , like new kernel installs , but as you will not know when these have taken place you may have to reboot on every update.
First the disclaimer: I have been using Linux since near the begining, and used to sysadmin Unix networks. I am fairly OCD/paranoid even with my home systems and always run updates interactively, and never with the "-y" switch. I want to know what is available for update and sometimes go investigate changes. I have pinned versions of things in the past. @pcmanbob's advice totally resonates with me.

Having said that, my perception is that with Raspbian, between distro updates, there is very little significant change, such that things like config files change. The rate of change in Linux also seems to be slowing at it matures, and Debian was never a hotbed of bleeding edge stuff to start with. What is the breakage risk for Raspbian with doing an auto update cron job as long as you are not upgrading to a new release?

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: Keepign PI4 up to date

Tue May 05, 2020 3:01 pm

bjtheone wrote:
Tue May 05, 2020 2:51 pm
Having said that, my perception is that with Raspbian, between distro updates, there is very little significant change, such that things like config files change. The rate of change in Linux also seems to be slowing at it matures, and Debian was never a hotbed of bleeding edge stuff to start with. What is the breakage risk for Raspbian with doing an auto update cron job as long as you are not upgrading to a new release?
Personally I'd rather have my updates happen when I order them. I don't want to find that one day I can't use a machine because it hosed itself with a bad update in the night. If it's going to break I'd like to be there to see what happened and try an fix it.

Having said that I first encountered a Debian machine that was configured to update every night in about 2000. I thought that is a crazy idea but in all the time I worked there it never failed. Since then I have almost never had Debian updates fail.

I'd like to think Raspbian, being derived from Debian, continues that tradition.
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Keepign PI4 up to date

Tue May 05, 2020 3:22 pm

What are you doing?
Use the unattened-upgrades package that's in DebIan.
https://wiki.debian.org/UnattendedUpgrades
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”