====== Intro ======
I made this script because I needed to know immediately when my mailcow server rebooted/crashed, as it requires manual actions to get started.
As mailcow itself makes it easy to use Pushover I thought why not use that as well as it works great.
So, here is a simple bash script you can run by itself or insert it into crontab.
===== crontab example =====
@reboot root bash /usr/local/bin/pushover.sh "System start up: $(hostname -f)" "$(hostname -f) rebooted!" 2
The script takes three parameters, message, title, and priority. I use priority 2 (emergency) as it will keep nagging me until I react.
===== pushover.sh =====
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: ./pushover [title] [priority]"
exit
fi
MESSAGE=$1
TITLE=$2
PRIORITY=${3:-0} # if you don't supply a priority it defaults to 0
if [ $# -lt 2 ]; then
TITLE="`whoami`@${HOSTNAME}"
fi
APP_TOKEN="XXXX"
USER_TOKEN="YYYYY"
BASE_URL="https://api.pushover.net/1/messages.json"
POST_DATA="token=$APP_TOKEN&user=$USER_TOKEN&message=$MESSAGE&title=$TITLE&priority=$PRIORITY"
# Check if $3 is set to 2 and append retry and expire parameters to POST_DATA
if [ "$PRIORITY" -eq 2 ]; then
POST_DATA="$POST_DATA&retry=60&expire=3600" # Just an example, you can set the values of retry and expire as per your needs
fi
curl -s -X POST -d "$POST_DATA" $BASE_URL > /dev/null 2>&1 &