This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Automatic weekly updates and reboot server if needed Ubuntu
#1
Automatic weekly updates and reboot server if needed Ubuntu
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:

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.
Reply
Thanks given by:


Messages In This Thread
Automatic weekly updates and reboot server if needed Ubuntu - by pinguy - 12-18-2015, 06:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Upgrade to Ubuntu 16.04 from 14.04 HogensHero 8 27 ,151 07-18-2020, 03:13 AM
Last Post: dycott78
Ubuntu: How to Enable tls/ssl in proftpd Diablo925 2 11 ,714 04-21-2020, 03:35 AM
Last Post: iraqiboy90
Ubuntu 18.04 or 20.04 Kangarooo 1 6 ,100 03-20-2020, 11:39 AM
Last Post: Jettaman

Forum Jump:


Users browsing this thread: 1 Guest(s)