9

I would like to setup my Raspberry Pi to tell me when it is up or down via the curl API of Pushover service. What are the steps to do this?

This came up while I was reading this question.

8

A lot of distributions, including Arch and Debian/Raspbian, use initscripts to initialise the system, and you can use them to run arbitrary commands. You need to install a script similar to the following in /etc/init.d.

#! /bin/sh
# /etc/init.d/pushover
#

# Some things that run always
touch /var/lock/pushover

TOKEN=
USER=

DIST=`cat /etc/os-release | perl -n -e '/^NAME=\"([a-zA-Z ]*)\"$/ && print "$1\n"'`

echo $TOKEN
echo $USER
echo $DIST

# Carry out specific functions when asked to by the system
case "$1" in
  start)
echo "Starting script pushover "
curl -s \
  --data-urlencode "token=$TOKEN" \
  --data-urlencode "user=$USER" \
  --data-urlencode "message=Raspberry Pi ($DIST) is starting." \
  https://api.pushover.net/1/messages
;;
  stop)
echo "Stopping script pushover"
curl -s \
  --data-urlencode "token=$TOKEN" \
  --data-urlencode "user=$USER" \
  --data-urlencode "message=Raspberry Pi ($DIST) is stopping." \
  https://api.pushover.net/1/messages
;;
  *)
echo "Usage: /etc/init.d/pushover {start|stop}"
exit 1
;;
esac

exit 0

You should register with the Pushover service and enter your app token in the TOKEN variable and your user key in the USER variable.

Test it in your home directory first, then move it to /etc/init.d/pushover. You should ensure it is runnable and owned by root.

sudo chmod 755 /etc/init.d/pushover
sudo chown root:root /etc/init.d/pushover

References

  1. How do I load a module at boot time?
  2. How do I access the distribution's name on the command line?
  3. Pushover

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.