Shell scripts
A small notify function for shell scripts and cron jobs: call it when a job is done or broken, and the message arrives in the topic. It works as copied, with the token on its first line; a token set in the environment is used instead.
Setting it up#
In the app this function is under Connect a system → Shell, or a topic's Send to this topic tab, with your address, the topic and a token filled in; New token makes the token.
A function for scripts and cron jobs. It works as copied; a SKIRL_TOKEN set in the environment is used instead of the token on its first line.
# The token. A SKIRL_TOKEN set in the environment (crontab, systemd unit, .env) wins; then the next line can go.
SKIRL_TOKEN="${SKIRL_TOKEN:-tk_replace_with_your_token}"
notify() {
curl -fsS "https://notify.example.com/backups" \
-H "Authorization: Bearer $SKIRL_TOKEN" \
-H "Title: $1" \
-d "$2" >/dev/null
}
notify "Nightly backup finished" "pve-01 → offsite. 14 VMs, no errors."Put the function near the top of the script, and call it with a title and a text wherever something is worth knowing, as its last line does. Skirl's tests run it as the app shows it, in a shell with no SKIRL_TOKEN set.
To keep the token out of the script, set SKIRL_TOKEN where the script runs and delete the token line: a SKIRL_TOKEN from the environment wins over the one in the script. Where the script runs is not your own terminal: a cron job or a service does not see your shell's variables. In a crontab, a line SKIRL_TOKEN=tk_replace_with_your_token above the jobs sets it for all of them. In a systemd service, set it in the unit's environment. With the line deleted and no SKIRL_TOKEN set, the function sends no token, and Skirl refuses with 403.
The function prints nothing when the message is taken. When Skirl refuses it, curl prints the reason and the function returns an error, so a script run with set -e stops there. If a failed notification should not stop the job, call it as notify "…" "…" || true.
A text of 4096 bytes or more, such as a whole log, arrives as a file attached to the message rather than as its text: Attachments. For a priority or tags, add a header line to the function, such as -H "Priority: 4" \: Title, priority and tags.
What a message looks like#
Nightly backup finished pve-01 → offsite. 14 VMs, no errors.
Priority 3
When nothing arrives#
Run the script by hand, in a terminal where SKIRL_TOKEN is set the way the script gets it (or not at all, when the token is in the script). curl's line says what happened:
curl: (22) The requested URL returned error: 403- 403: the token line was deleted and
SKIRL_TOKENis empty or not set where the script runs (the usual cause in cron), or the token may not send to this topic: it is limited to another one, or the topic name is misspelled. - 401: the token is wrong, revoked or expired. Make a new one with New token, or Rotate, and set it again.
- 404: the address is not a topic's: it must be your server's address, a
/and the topic name, nothing after it. - 429: too many messages too fast, or too many failed sign-ins from this address: Rate limits.
Could not resolve host, a timeout orSSL certificate problem: this machine cannot reach the server, or does not trust its certificate.
To see Skirl's whole answer rather than only its status, send the same message with plain curl: curl. The general checks: A sender gets no message through. Every error code: Error messages.