commit 736e8079be62bb744ae4a172405422bda0780565 parent ebd97f90873f71b4849f65cc427e6d3cbaaf26eb Author: Chris Roberts <chris.roberts@learningunix.net> Date: Mon, 1 Jun 2026 09:12:15 -0500 added error checking and messages. The script will now notify the user of correct usage, handle dirty input as best it can, log curl and pushover errors. Diffstat:
| M | notify.sh | | | 26 | ++++++++++++++++++++++---- |
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/notify.sh b/notify.sh @@ -1,8 +1,26 @@ #!/bin/sh -/usr/bin/curl -s \ +if [ "$#" -lt 2 ]; then + echo "Usage: notify.sh <title> <message>" >&2 + exit 1 +fi + +title="$1" +shift +message="$*" + +output=$(/usr/bin/curl -s \ --form-string "token=$PUSHOVER_TOKEN" \ --form-string "user=$PUSHOVER_USER" \ - --form-string "title=$1" \ - --form-string "message=$2" \ - https://api.pushover.net/1/messages.json + --form-string "title=$title" \ + --form-string "message=$message" \ + https://api.pushover.net/1/messages.json 2>&1) +code=$? + +if [ "$code" -ne 0 ]; then + logger -t notify.sh "curl failed (exit $code): $output" +elif + echo "$output" | grep -q '"status":0' +then + logger -t notify.sh "pushover rejected message: $output" +fi