Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'net/smtp'
- # Only reboot if these packages are updated
- flagged = ['linux']
- # Some required SMTP vars
- smtp_server = ''
- smtp_port = 25
- smtp_helo = ''
- smtp_username = ''
- smtp_password = ''
- email = ''
- smtp_msg = <<EOF
- From:
- To:
- Subject:
- Updating via pacman failed. Investigate ASAP.
- EOF
- reboot = false
- # See what packages have updates available
- updates = `/usr/bin/pacman -Qu`
- if $?.exitstatus == 0 # Perform updates if they're available
- # If any of our previously flagged packages have updates, schedule a reboot
- flagged.each do |pkg|
- reboot = true if updates =~ /^\b#{pkg}\b(?!-)/
- end
- # Perform the updates
- system('/usr/bin/pacman -Syu --noconfirm > /dev/null 2>&1')
- # Send out an email if anything went wrong
- if $?.exitstatus != 0
- Net::SMTP.start(smtp_server, smtp_port, smtp_helo, smtp_username, smtp_password, :plain) do |smtp|
- smtp.send_message smtp_msg, email, email
- end
- end
- # Reboot the host if any flagged packages were updated
- if reboot
- system('reboot')
- end
- end
Add Comment
Please, Sign In to add comment