Automatic weekly updates and reboot server if needed Ubuntu
12-18-2015, 06:10 AM
(This post was last modified: 02-03-2016, 12:42 PM by pinguy.)
I have been running this for just over 2 years without any issues. This includes the script updating MySQL. But your usage may very. So use with caution.
To do weekly updates and reboot server if needed run:
Also make sure you edit fsck so it forces the fix.
Change the line at the end of that file to:
from:
F3 will save the file and Ctrl+X will exit nano.
To do weekly updates and reboot server if needed run:
Code:
nano /etc/cron.weekly/updater
Code:
#!/bin/bash
/usr/bin/dpkg --configure -a
/usr/bin/apt-get update
/usr/bin/apt-get -qy dist-upgrade
/usr/bin/apt-get install -f
/usr/bin/apt-get clean
/usr/bin/apt-get -qy autoremove
if [ -f /var/run/reboot-required ]; then
sudo touch /forcefsck
sudo reboot
else
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
exit 0
fi
Code:
sudo chmod +x '/etc/cron.weekly/updater'
sudo chmod 755 '/etc/cron.weekly/updater'
Also make sure you edit fsck so it forces the fix.
Code:
nano /etc/default/rcS
Change the line at the end of that file to:
Code:
FSCKFIX=yes
from:
Code:
#FSCKFIX=no
F3 will save the file and Ctrl+X will exit nano.