Last active
August 29, 2015 14:05
-
-
Save craigloftus/8df01f5fe11958349c64 to your computer and use it in GitHub Desktop.
This is an ultra simple shell script to send an email notification if an Ubuntu machine needs a reboot for packages to be upgraded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Simple script to send an email when a server restart is required. | |
# Requires mailutils package and will send the email to the local user by default. | |
if [ ! -f /var/run/reboot-required ]; then | |
# No reboot required | |
exit 0 | |
else | |
# Reboot required, so notify by email | |
USER=$(whoami) | |
PACKAGE=`cat /var/run/reboot-required.pkgs` | |
/usr/bin/mail -s "Reboot required on $HOSTNAME" $USER<<EOF | |
Some packages require a reboot for their upgrades to be applied on $HOSTNAME: | |
$PACKAGE | |
EOF | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment