Skip to content

Instantly share code, notes, and snippets.

@roelentless
Last active August 29, 2015 14:07
Show Gist options
  • Save roelentless/ddfbc06335bb53bc08f2 to your computer and use it in GitHub Desktop.
Save roelentless/ddfbc06335bb53bc08f2 to your computer and use it in GitHub Desktop.
Auto update ubuntu servers
#!/bin/bash
# Put this script in your /etc/cron.daily or schedule it through crontab. It should run as root and have x permissions.
# roelb unattended autoupdate
echo "" >> /var/log/autoupdate
echo "*****" >> /var/log/autoupdate
date >> /var/log/autoupdate
echo "Updating aptitude..." >> /var/log/autoupdate
aptitude update >> /var/log/autoupdate
echo "Safe-upgrade..." >> /var/log/autoupdate
aptitude safe-upgrade -o Aptitude::Delete-Unused=false --assume-yes >> /var/log/autoupdate
if [ -f /var/run/reboot-required ]; then
echo "Reboot required, rebooting..." >> /var/log/autoupdate
reboot
else
echo "No reboot required, bouncing services..." >> /var/log/autoupdate
# Keep services fresh
# service mysql restart >> /var/log/autoupdate
service apache2 restart >> /var/log/autoupdate
sleep 10
service spamassassin restart >> /var/log/autoupdate
sleep 10
service clamav-daemon restart >> /var/log/autoupdate
sleep 10
service dovecot restart >> /var/log/autoupdate
sleep 10
service postfix restart >> /var/log/autoupdate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment