Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Boot email notification by Charlton Trezevant
# Version 3.0
# Just paste it right in to /etc/rc.local
# Note that this depends on having mailx and postfix installed.
# See below for more info.
# This script requires mailx and postfix to be installed.
# Install mailx like so: sudo apt-get install bsd-mailx
# You can then create an email address for your pi and send outgoing mail through that
# (see, Or, if you prefer,
# you could also use your own mailserver at your domain.
# At the top of the script are 3 different variables.
# --
# The first is EMAIL. This should contain the email address to which messages should be sent. If you like, you can add multiple
# addresses, separated by commas. This can either be your email, or your phone's SMS email ( for SMS-to-email info)
# --
# The second is HOST. This automatically gets the machines hostname and requires no configuration on the part of the user.
# --
# The third is the LAN interface that the LAN IP should be pulled from. Usually, this is eth0, but it could also be em0.
# run ifconfig to see the list of available interfaces. Change this if you want to get the IP of a different network interface than
# the default.
# Also, on some systems, /sbin/ifconfig is not installed. This command is usually replaced with /sbin/ip, with addresses shown using
# The command "ip addr".
# Should this be the case, try using the following command:
# /bin/ip addr | /bin/grep inet | /usr/bin/tail -n 2 | /usr/bin/head -n 1
# Which should produce somethinf along the lines of:
# inet brd scope global eth0
HOST="$(cat /etc/hostname)"
echo "
$HOST has booted!
System information:
Date and time:
`date +"%A, %e %B %Y, %r"`
Uptime (length of boot):
Network addresses:
LAN: `/sbin/ifconfig $LANIFACE | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1`
WAN: `timeout 6 dig +short`
Disk usage:
`df -kh /`
" | mailx -s $HOST' Has Booted!' $EMAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment