Advertisement
ShapeShifter499

auto upgrade script

Jun 5th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. # This is a script made to keep your Ubuntu server up to
  2. # date placing this script to /etc/cron.weekly/autoupdate.sh.
  3. # This script updates your server automatically and informs
  4. # you via email if the update was succesful or not.
  5.  
  6. # Set the variable $admin_email as your email address.
  7. admin_mail="your.name@email.com"
  8.  
  9. # Create a temporary path in /tmp to write a temporary log
  10. # file. No need to edit.
  11. tmpfile=$(mktemp)
  12.  
  13. # Run the commands to update the system and write the log
  14. # file at the same time.
  15. echo "aptitupde update" >> ${tmpfile}
  16. aptitude update >> ${tmpfile} 2>&1
  17. echo "" >> ${tmpfile}
  18. echo "aptitude full-upgrade" >> ${tmpfile}
  19. aptitude -y full-upgrade >> ${tmpfile} 2>&1
  20. echo "" >> ${tmpfile}
  21. echo "aptitude clean" >> ${tmpfile}
  22. aptitude clean >> ${tmpfile} 2>&1
  23.  
  24. # Check if the system needs a reboot
  25. echo /etc/update-motd.d/98-reboot-required >> ${tmpfile}
  26.  
  27. # Send the temporary log via mail. The fact if the upgrade
  28. # was succesful or not is written in the subject field.
  29. if grep -q 'E: \|W: ' ${tmpfile} ; then
  30. mail -s "Upgrade of your server failed $(date)" ${admin_mail} < ${tmpfile}
  31. elif grep -q 'System restart required' ${tmpfile} ; then
  32. mail -s "Upgraded your server successfully and rebooted $(date)" ${admin_mail} < "System reboot was required" ${tmpfile}
  33. else
  34. mail -s "Upgraded your server successfully (No Reboot $(date)" ${admin_mail} < "System reboot was not required" ${tmpfile}
  35. fi
  36.  
  37.  
  38.  
  39. # Remove the temporary log file in temporary path.
  40. rm -f ${tmpfile}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement