notify.sh (756B)
1 #!/bin/sh 2 3 if [ -z "$PUSHOVER_USER" ] || [ -z "$PUSHOVER_TOKEN" ]; then 4 echo "Warning: Pushover user and token are not set" >&2 && logger -t notify.sh "pushover credentials cannot be found" 5 exit 1 6 fi 7 8 if [ "$#" -lt 2 ]; then 9 echo "Usage: notify.sh <title> <message>" >&2 10 exit 1 11 fi 12 13 title="$1" 14 shift 15 message="$*" 16 17 output=$(/usr/bin/curl -s \ 18 --form-string "token=$PUSHOVER_TOKEN" \ 19 --form-string "user=$PUSHOVER_USER" \ 20 --form-string "title=$title" \ 21 --form-string "message=$message" \ 22 https://api.pushover.net/1/messages.json 2>&1) 23 code=$? 24 25 if [ "$code" -ne 0 ]; then 26 logger -t notify.sh "curl failed (exit $code): $output" 27 elif 28 echo "$output" | grep -q '"status":0' 29 then 30 logger -t notify.sh "pushover rejected message: $output" 31 fi