Skip to content

Instantly share code, notes, and snippets.

@craigloftus
Last active August 29, 2015 14:05
Show Gist options
  • Save craigloftus/8df01f5fe11958349c64 to your computer and use it in GitHub Desktop.
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.
#!/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