Monitor Bash Cron Scripts
Learn how to add Haspulse monitoring to shell scripts and system cron jobs.
Features
- Single curl command integration
- Works with any shell (bash, zsh, sh)
- Supports exit code detection
- Retry with exponential backoff
Code Examples
Basic ping
#!/bin/bash
# Add to end of any cron script
# Simple ping on success
curl -fsS --retry 3 https://haspulse.io/ping/YOUR_CHECK_ID
# With start signal
curl -fsS https://haspulse.io/ping/YOUR_CHECK_ID/start
# ... your script logic ...
curl -fsS https://haspulse.io/ping/YOUR_CHECK_IDWith error handling
#!/bin/bash
CHECK_URL="https://haspulse.io/ping/YOUR_CHECK_ID"
# Signal start
curl -fsS "$CHECK_URL/start"
# Run your job and capture exit code
/path/to/your/backup-script.sh
EXIT_CODE=$?
# Ping based on result
if [ $EXIT_CODE -eq 0 ]; then
curl -fsS "$CHECK_URL"
else
curl -fsS "$CHECK_URL/fail"
fi
exit $EXIT_CODECrontab entry
# Edit with: crontab -e
# Database backup at 3 AM daily
0 3 * * * /home/user/backup.sh && curl -fsS https://haspulse.io/ping/BACKUP_ID
# Queue processor every 5 minutes
*/5 * * * * /home/user/process-queue.sh; curl -fsS https://haspulse.io/ping/QUEUE_ID
# With full lifecycle
0 * * * * curl -fsS https://haspulse.io/ping/HOURLY_ID/start && /home/user/hourly-job.sh && curl -fsS https://haspulse.io/ping/HOURLY_ID || curl -fsS https://haspulse.io/ping/HOURLY_ID/failHow It Works
- 1Create a check in HaspulseSet your expected schedule (e.g., every 5 minutes)
- 2Add the ping to your codePing the unique URL when your job runs successfully
- 3Get alerted on failuresIf a ping doesn't arrive on time, we notify you
Related Integrations
Start monitoring in minutes
Create your first check and start receiving alerts when your scheduled jobs fail.
Get started free