Shell Scripts
Ping Cronping from Bash and shell scripts.
Basic usage
#!/bin/bash
set -e
# Your job logic here
/usr/bin/backup.sh
# Ping Cronping on success
curl -fsS https://ping.cronping.com/<token>Using set -e causes the script to exit immediately on any error, which means the ping call at the end only runs if everything above it succeeded.
Wrapper pattern
A robust pattern for wrapping any command:
#!/bin/bash
PING_URL="https://ping.cronping.com/<token>"
JOB_CMD="/usr/bin/backup.sh"
# Run the job
if "$JOB_CMD"; then
# Success — ping Cronping
curl -fsS --max-time 10 "$PING_URL"
else
echo "Job failed with exit code $?" >&2
# Do not ping — Cronping will alert via the missed heartbeat
fiCapturing output and pinging
#!/bin/bash
PING_URL="https://ping.cronping.com/<token>"
LOG_FILE="/var/log/my-job.log"
echo "=== Starting job $(date) ===" >> "$LOG_FILE"
if /usr/bin/my-job.sh >> "$LOG_FILE" 2>&1; then
curl -fsS --max-time 10 "$PING_URL" > /dev/null
echo "Job succeeded and Cronping notified" >> "$LOG_FILE"
else
echo "Job FAILED" >> "$LOG_FILE"
fiRunning from crontab
# Run every day at 3 AM
0 3 * * * /usr/local/bin/backup-with-ping.sh >> /var/log/backup.log 2>&1Environment variables
If you manage multiple heartbeats, store tokens as environment variables:
#!/bin/bash
# Load from .env or /etc/environment
BACKUP_PING_URL="https://ping.cronping.com/<token>"
/usr/bin/backup.sh && curl -fsS --max-time 10 "$BACKUP_PING_URL"cron one-liner (recommended for simple jobs)
For simple jobs, you don't need a wrapper script:
0 3 * * * /usr/bin/backup.sh && curl -fsS --max-time 10 https://ping.cronping.com/<token>Measuring run duration with /start
Send a /start ping before the job begins and a success ping after. Cronping will measure and display the duration:
#!/bin/bash
set -e
PING_URL="https://ping.cronping.com/<token>"
curl -fsS --max-time 10 "$PING_URL/start"
/usr/bin/backup.sh
curl -fsS --max-time 10 "$PING_URL"If no success or fail ping arrives within the grace period after /start, Cronping will mark the heartbeat as Down.
Reporting exit codes
Pass the shell exit code directly in the URL — 0 is success, anything else is failure:
#!/bin/bash
PING_URL="https://ping.cronping.com/<token>"
/usr/bin/backup.sh
curl -fsS --max-time 10 "$PING_URL/$?"Signaling failure explicitly
Use /fail to immediately trigger a Down alert without waiting for the grace period:
#!/bin/bash
PING_URL="https://ping.cronping.com/<token>"
curl -fsS --max-time 10 "$PING_URL/start"
if /usr/bin/backup.sh; then
curl -fsS --max-time 10 "$PING_URL"
else
curl -fsS --max-time 10 "$PING_URL/fail"
fi