Skip to content

Instantly share code, notes, and snippets.

@chtzvt
Last active September 7, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chtzvt/850effec75aa2e0a92fa to your computer and use it in GitHub Desktop.
Save chtzvt/850effec75aa2e0a92fa to your computer and use it in GitHub Desktop.
linux-boot-notify
# Boot email notification by Charlton Trezevant
# Version 3.0
###SETUP:
# Just paste it right in to /etc/rc.local
# Note that this depends on having mailx and postfix installed.
# See below for more info.
###DEPENDENCIES
# 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 https://www.linode.com/docs/email/postfix/postfix-smtp-debian7), Or, if you prefer,
# you could also use your own mailserver at your domain.
###CONFIGURATION
# 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 (http://goo.gl/hhAABm 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 192.168.0.12/24 brd 10.0.1.255 scope global eth0
EMAIL='<your_email>@example.com'
HOST="$(cat /etc/hostname)"
LANIFACE='eth0'
echo "
$HOST has booted!
System information:
Date and time:
`date +"%A, %e %B %Y, %r"`
Uptime (length of boot):
`uptime`
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 myip.opendns.com @resolver1.opendns.com`
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