Guide · crontab
Monitor a crontab job
Paste the five schedule fields from the crontab line, then add one curl to the same line.
1. Create the monitor from the crontab line
Paste the first five fields of the line. Pick the zone the server's cron runs in, because that is the zone the schedule is read in.
2. Add the ping to the same line
Chain the ping with &&, so that it only runs when the job succeeds.
0 2 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 -o /dev/null https://ping.cronwize.com/YOUR-KEY-fsShides the progress output and still reports errors, and treats an HTTP error as a failed command.-m 10stops a slow ping from holding the job open.-o /dev/nullkeeps theOKresponse out of cron's mail.
With only this line, a failure looks the same as a job that never ran: the monitor goes down when the grace period ends.
3. Report failures and output at once
To alert immediately and include the job's output, put the job in a small wrapper and point the crontab at that.
#!/bin/sh
PING=https://ping.cronwize.com/YOUR-KEY
curl -fsS -m 10 -o /dev/null "$PING/start"
if output=$(/usr/local/bin/backup.sh 2>&1); then
curl -fsS -m 10 -o /dev/null "$PING"
else
printf '%s' "$output" | curl -fsS -m 10 -o /dev/null --data-binary @- "$PING/fail"
fiThe first 10 KB of the body are kept in the ping log, and the first 500 characters go into the alert. Do not send secrets.
4. Check the first ping
Run the job once by hand. The monitor turns from new to up.