Skip to content

Instantly share code, notes, and snippets.

@robshep
Created December 14, 2013 22:09
Show Gist options
  • Save robshep/7965568 to your computer and use it in GitHub Desktop.
Save robshep/7965568 to your computer and use it in GitHub Desktop.
LSB start/stop script to email when a Pi starts/stops (change variables!)
#!/bin/sh
### BEGIN INIT INFO
# Provides: piboot
# Required-Start: $ntp $network $remote_fs $syslog
# Required-Stop: $ntp $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Emails out when the pi boots/shutsdown
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
export MANDRILL_KEY=<your mandrill key>
export EMAIL_ADDRESS=<youremail address>
export PI_NAME=<your Pi's name>
email() {
STATUS=$1
LIP=`hostname -I`
DATE=`date`
curl --trace-ascii -A 'Mandrill-Curl/1.0' -d @- 'https://mandrillapp.com/api/1.0/messages/send.json' <<- EOF
{ "key" : "$MANDRILL_KEY",
"message" : { "from_email" : "$EMAIL_ADDRESS",
"from_name" : "Pi[$PI_NAME]",
"subject" : "Pi[$PI_NAME] - $STATUS ",
"tags" : [ "piboot" ],
"text" : "Pi[$PI_NAME] is $STATUS ($LIP) $DATE",
"to" : [ { "email" : "$EMAIL_ADDRESS",
"name" : "Pie Master",
"type" : "to"
} ]
}
}
EOF
}
email_booting() {
echo "boot"
}
email_shutdown() {
echo "shutdown"
}
case $1 in
start)
email booting
;;
stop)
email "shutting down"
;;
*)
echo "Usage: $0 {start|stop}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment