Skip to content

Instantly share code, notes, and snippets.

@MichaelKreil
Last active January 6, 2021 11:36
Show Gist options
  • Save MichaelKreil/306e07f1aa3ac7481c355265bb76baa5 to your computer and use it in GitHub Desktop.
Save MichaelKreil/306e07f1aa3ac7481c355265bb76baa5 to your computer and use it in GitHub Desktop.
small bash script that sends you notifications with debug informations when your cronjob scripts fail
#!/bin/bash
result=$(exec $2 2>&1)
status=$?
if [ $status -eq 0 ]; then
exit 0
fi
curl -s -o /dev/null --form-string "token=APITOKEN" --form-string "user=USERKEY" --form-string "title=$1" --form-string "message=$result" https://api.pushover.net/1/messages.json
# How to use it?
# 1. Signup to pushover.net, pay the 5$ as a one-time purchase.
# 2. Install the pushover app on your phone, login and connect the app with your pushover account.
# 3. Copy the user key from here https://pushover.net/ and replace the curl parameter "USERKEY"
# 4. Create a new app (https://pushover.net/apps/build), copy the API token and replace the curl parameter "APITOKEN"
# 5. Copy this bash script to your server, e.g. as "notificato.sh". Make sure it is executable (chmod +x notificato.sh)
# 6. Update your cronjobs. Instead of running e.g. 'cronjob_script.sh' run 'notificato.sh "hourly script" cronjob_script.sh'
# The first parameter is the title of the notification.
# The second parameter is your script to be executed.
# If your cronjob script fails with an error, you will receive a notification on your phone with the given title and the results of stdout and stderr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment