Docs Ping PingArk from a shell script or cron job

Ping PingArk from a shell script or cron job

The quickest way to monitor a cron job is a single curl to the ping URL of your check. Run the job, and if it succeeds, curl the URL. If that ping does not arrive on schedule, PingArk alerts you. This works from any shell, on any host, with no library to install.

Before you start

You need a check and its ping URL. Create one in the dashboard, then copy the ping URL from the check page. New to PingArk? Start with the getting started guide.

Ping on success

Call the ping URL after your job finishes its work. A plain ping means success and re-arms the check for its next run.

curl -fsS -m 10 --retry 3 https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e
Copy
# Run the job, then ping on success.
*/5 * * * * /path/to/job.sh && curl -fsS -m 10 --retry 3 https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e
Copy
#!/usr/bin/env bash
set -e
/path/to/job.sh
curl -fsS -m 10 --retry 3 https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e
Copy

Report failures, starts and duration

Add a suffix to the ping URL to say more than a plain success. Call these the same way you called the success URL above. The ping API has the full reference.

https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e        # success: the job finished, re-arms the timer
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/start  # the run started, lets PingArk measure duration
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/fail   # an explicit failure, alerts right away
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/log    # a timeline note, never alerts
https://ping.pingark.com/ping/3f9c2a1b-7d4e-4c8a-9f1b-2e6d8a0c4b5e/$?     # a shell exit code: 0 is success, anything else fails
Copy

The -fsS flags keep curl quiet on success but let it fail loudly on an error, and -m 10 caps the request at ten seconds so a slow network never hangs the job. --retry 3 rides out a brief blip.

To ping only when the job actually succeeds, chain the curl after your command with &&, as in the crontab example. That way a failed job never reports success.

To measure how long a job runs, ping the /start URL first, then the success URL at the end. To alert the moment a job fails, ping /fail, or append the shell exit code with /$?.

Troubleshooting

  • No ping showing up? Run the curl by hand and confirm it prints nothing and exits zero. A firewall or proxy that blocks outbound HTTPS is the usual cause.
  • Cron runs with a minimal environment. Use full paths to curl and to your script, and remember that cron does not load your shell profile.