Tell me more ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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 to me while reading this question.

share|improve this question

1 Answer

up vote 6 down vote accepted

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 run a command at boot?
  2. How do I access the distribution's name on the command line?
  3. Pushover
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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