blog.awill.me

blog.awill.me

09 Nov 2021

Pushover

I’ve been using Pushover since 2012. It’s a service that allows you to programmatically send instant push notifications to your devices.
You just install the app on your phone and get an API key. Then you just call the API with your tokens to send notifications. For the last 9 years I’ve really only used this to get notifications on uptime using Uptime Robot. If my website, home server, or home internet are down, Uptime Robot sends a notification to my phone. It’s extremely simple, and has no subscription fees. Pushover is just a one-time $5 purchase on Android. It has some more advanced functionality like a Do Not Disturb schedule per device or client, customer notification sounds, and the ability to send certain notifications to specific devices etc.. but I don’t use any of that. This app is obviously designed for much more advanced usecases, but for $5, I’d rather get these sorts of notifications in one app vs an email.

When I moved my websites to Hugo running on netlify in 2017, I configured netlify to send pushover notifications when it published new versions of each of my websites (or encountered errors publishing). There’s no point in refreshing my browser over and over until netlify actually publishes the site. Now I wait for the notification and refresh just once. Simple, but effective.

Lately I’ve been running some long-running tasks on my Linux server at home. Whether it’s copying a lot of data, encoding, or encrypting something, I want to know when the task completes without having to periodically check. I figured I should take advantage of Pushover to send myself a notification when the task completes. Since I generally perform these server tasks SSH’d onto my server, it was simple to just add the following to my .bashrc file.

pushover() {
    APP_TOKEN='MY_TOKEN'
    USER_TOKEN='MY_USER_KEY'
    TITLE="server-01"
    MESSAGE="$1"
    curl 'https://api.pushover.net/1/messages.json' -X POST -d "token=$APP_TOKEN&user=$USER_TOKEN&message=\"$MESSAGE\"&title=\"$TITLE\""
}

Then all I have to do when running a command is append ‘; pushover MY_MESSAGE.

e.g. cp -Rf * /mnt/HD2 ; pushover "copy complete" That’s it. When the first command completes, it will run the pushover command and send me a notification with whatever message I want. This is one of those trivial things I wish I’d done sooner.

Categories