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_ID
With 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_CODE
Crontab 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/fail

How It Works

  1. 1
    Create a check in Haspulse
    Set your expected schedule (e.g., every 5 minutes)
  2. 2
    Add the ping to your code
    Ping the unique URL when your job runs successfully
  3. 3
    Get alerted on failures
    If 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