Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a script made to keep your Ubuntu server up to
- # date placing this script to /etc/cron.weekly/autoupdate.sh.
- # This script updates your server automatically and informs
- # you via email if the update was succesful or not.
- # Set the variable $admin_email as your email address.
- admin_mail="your.name@email.com"
- # Create a temporary path in /tmp to write a temporary log
- # file. No need to edit.
- tmpfile=$(mktemp)
- # Run the commands to update the system and write the log
- # file at the same time.
- echo "aptitupde update" >> ${tmpfile}
- aptitude update >> ${tmpfile} 2>&1
- echo "" >> ${tmpfile}
- echo "aptitude full-upgrade" >> ${tmpfile}
- aptitude -y full-upgrade >> ${tmpfile} 2>&1
- echo "" >> ${tmpfile}
- echo "aptitude clean" >> ${tmpfile}
- aptitude clean >> ${tmpfile} 2>&1
- # Check if the system needs a reboot
- echo /etc/update-motd.d/98-reboot-required >> ${tmpfile}
- # Send the temporary log via mail. The fact if the upgrade
- # was succesful or not is written in the subject field.
- if grep -q 'E: \|W: ' ${tmpfile} ; then
- mail -s "Upgrade of your server failed $(date)" ${admin_mail} < ${tmpfile}
- elif grep -q 'System restart required' ${tmpfile} ; then
- mail -s "Upgraded your server successfully and rebooted $(date)" ${admin_mail} < "System reboot was required" ${tmpfile}
- else
- mail -s "Upgraded your server successfully (No Reboot $(date)" ${admin_mail} < "System reboot was not required" ${tmpfile}
- fi
- # Remove the temporary log file in temporary path.
- rm -f ${tmpfile}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement