Bash
Last updatedยท1 min read
Send push notifications from shell scripts, cron jobs, and automation workflows.
Basic example
curl -s -X POST https://thenotification.app/api/sendNotification \
-H "app_key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"title": "Alert", "body": "Something happened"}'
Reusable function
Add this function to your .bashrc or .zshrc, or source it in your scripts:
notify() {
local title="$1"
local body="$2"
curl -s -X POST https://thenotification.app/api/sendNotification \
-H "app_key: ${NOTIFICATION_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"title\": \"${title}\", \"body\": \"${body}\"}" \
> /dev/null
}
# Usage
notify "Build done" "main branch built successfully"
Set your API key as an environment variable:
export NOTIFICATION_API_KEY=your_api_key_here
Notify on command completion
Run any command and get notified when it finishes:
long-running-command && notify "Done" "Command finished successfully" \
|| notify "Failed" "Command exited with an error"
Cron job notifications
Wrap any cron job to get notified on failure:
#!/bin/bash
# /usr/local/bin/notify-on-fail.sh
NOTIFICATION_API_KEY=your_api_key_here
run_job() {
/path/to/your/script.sh
}
if ! run_job; then
curl -s -X POST https://thenotification.app/api/sendNotification \
-H "app_key: ${NOTIFICATION_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"title\": \"Cron job failed\", \"body\": \"$(hostname) โ $(date)\"}"
fi
Add to crontab:
0 2 * * * /usr/local/bin/notify-on-fail.sh