Guest User

Untitled

a guest
Nov 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'net/smtp'
  4.  
  5. # Only reboot if these packages are updated
  6. flagged = ['linux']
  7.  
  8. # Some required SMTP vars
  9. smtp_server = ''
  10. smtp_port = 25
  11. smtp_helo = ''
  12. smtp_username = ''
  13. smtp_password = ''
  14. email = ''
  15. smtp_msg = <<EOF
  16. From:
  17. To:
  18. Subject:
  19.  
  20. Updating via pacman failed. Investigate ASAP.
  21. EOF
  22.  
  23. reboot = false
  24.  
  25. # See what packages have updates available
  26. updates = `/usr/bin/pacman -Qu`
  27.  
  28. if $?.exitstatus == 0 # Perform updates if they're available
  29. # If any of our previously flagged packages have updates, schedule a reboot
  30. flagged.each do |pkg|
  31. reboot = true if updates =~ /^\b#{pkg}\b(?!-)/
  32. end
  33.  
  34. # Perform the updates
  35. system('/usr/bin/pacman -Syu --noconfirm > /dev/null 2>&1')
  36.  
  37. # Send out an email if anything went wrong
  38. if $?.exitstatus != 0
  39. Net::SMTP.start(smtp_server, smtp_port, smtp_helo, smtp_username, smtp_password, :plain) do |smtp|
  40. smtp.send_message smtp_msg, email, email
  41. end
  42. end
  43.  
  44. # Reboot the host if any flagged packages were updated
  45. if reboot
  46. system('reboot')
  47. end
  48. end
Add Comment
Please, Sign In to add comment