Skip to content

Hooks and recipes / Shell one-liners

Shell one-liners

A push() function and one-liners for scripts, cron jobs and long commands.

The quickest way to get a notification from a terminal, a script or a cron job is a hook: one curl with a title header, no JSON and no API key. Create a hook on the recipient's page in the dashboard and keep its URL in an environment variable:

⫻

shell

export PUSH_HOOK="https://api.meslzy.com/push/v1/hooks/hk_9Qm2Xv7Lc4Tz8Rb1Nw6Ks3Jd5Yf0Hg2P"

A push function#

Add this to ~/.bashrc or ~/.zshrc, or to the top of a script:

⫻

push()

push() {  local title="$1"  local body="${2-}"
  if [ "$#" -lt 2 ] && [ ! -t 0 ]; then    body="$(cat)"  fi
  curl --fail-with-body -sS -w '\n' "$PUSH_HOOK" \    -H "Title: $title" \    -H "Priority: ${PUSH_PRIORITY:-default}" \    --data-binary "$body"}
  • The first argument is the title. The second, if given, is the body; otherwise the body is read from a pipe.
  • PUSH_PRIORITY sets the priority with the hook's values: low, default, high or urgent. default sends with priority high.
  • --fail-with-body makes push fail with curl's exit code and print Push's error when the request is refused. It needs curl 7.76 or later; drop it on older systems.

⫻

usage

push "Deploy finished"push "Deploy finished" "api@4f2c1a is live in production"df -h / | push "Disk report"PUSH_PRIORITY=urgent push "Disk full on db-1"

When a long command finishes#

Run the command, then report its exit code. $? is read before push runs, so it is the command's own code:

⫻

shell

./migrate-all.sh; push "Done: $?"

Only when something fails#

|| runs push only when the command before it exits with an error:

./backup.sh || push "backup failed on $(hostname)"

Without the function#

Where defining a function is not handy, one curl does the same:

⫻

curl

curl -sS "$PUSH_HOOK" -H "Title: Build finished" -d "exit code $?"

In a crontab#

Cron does not read your shell profile, so set the hook URL at the top of the crontab and call curl directly:

⫻

crontab -e

PUSH_HOOK=https://api.meslzy.com/push/v1/hooks/hk_9Qm2Xv7Lc4Tz8Rb1Nw6Ks3Jd5Yf0Hg2P0 3 * * * /usr/local/bin/backup.sh || curl -sS "$PUSH_HOOK" -H "Title: Backup failed" -H "Priority: urgent" --data-binary "host $(hostname)"
NoteCron treats % specially in a command line. Keep date formats like +%F in a script rather than in the crontab line.

With an API key and safe retries#

To send through the API instead, for example to pick the recipient or use message options, post JSON with an API key. An Idempotency-Key (up to 255 characters) tied to the job lets curl retry without sending twice. This version uses jq to build the JSON safely:

push_api() {  curl --fail-with-body -sS -w '\n' \    --retry 3 --retry-all-errors \    "https://api.meslzy.com/push/v1/notifications" \    -H "Authorization: Bearer $PUSH_API_KEY" \    -H "Content-Type: application/json" \    -H "Idempotency-Key: $2" \    --data "$(jq -cn --arg title "$1" '{recipient: "me", title: $title}')"}
  • Pick a key that names the event, like backup-2026-10-05. Running the same job twice in a day then sends one notification, and a retry after a network error replays the first answer. See Idempotency.
  • --retry-all-errors needs curl 7.71 or later.
  • Keep PUSH_API_KEY on the server. Live keys are refused from browsers; see Authentication.