Auto Update Debian Server Script

Sometimes it's nice to have a server notify you when updates are available. If you're brave, it's nice to have the server automatically update itself for you.


Here is a handy little script that I scrounged up a long time ago and have been using it very successfully. I manually log in and run the updates during off-hours, but if you're confident that your server won't have any problems, then you can uncomment the line that runs the udpate and have an auto-updating server.


I use the mailx command to send the attachment, but it would be easy enough for you to rewrite it to use sendmail if that is what you require.


# Runs apt-get update and notifies the administrator of any updates.
# Optionally runs the updates automatically.

if [[ `apt-get update 2>&1 | grep Get` ]]; then
	if [[ `apt-get --simulate dist-upgrade 2>&1 | grep Inst` ]]; then
		apt-get --simulate dist-upgrade > /root/scripts/check_updates.log
		# If you just want mail notification, use the following line
		mailx -s "Servername needs updates" < /root/scripts/check_updates.log
		# If you want the update to be run no matter what, uncomment the following line
		# apt-get dist-upgrade

Back to Article Index

blog comments powered by Disqus