Bash Heartbeat - Code Examples
Monitor your shell scripts and crons with a simple curl.
Bash scripts are everywhere: system crons, deployments, backups, maintenance. A simple curl is enough to integrate MoniTao heartbeat.
Here are the most robust methods to ping MoniTao from your shell scripts.
Standard method: curl
The simplest and most universal method:
#!/bin/bash\nset -e\n\n# Your script\n./backup.sh\n\n# Ping MoniTao\ncurl -s -X POST https://monitao.com/api/heartbeat/ping/YOUR_TOKEN
Alternative: wget
If curl isn't available:
wget -q --post-data= https://monitao.com/api/heartbeat/ping/YOUR_TOKEN -O /dev/null
seo.heartbeat_bash.script_title
seo.heartbeat_bash.script_intro
seo.heartbeat_bash.script_example
FAQ - Bash Heartbeat
Why "|| true" at the end of curl?
With "set -e", the script stops on the first error. "|| true" prevents the script from failing if the ping fails. Your job is done, the ping is a bonus.
How do I ping only if my script succeeds?
Use "set -e" at the beginning of the script. Any failing command stops the script before the ping. Or explicitly test the return code.
Can I use heartbeat directly in a crontab?
Yes: "0 * * * * /path/script.sh && curl -s -X POST https://monitao.com/api/heartbeat/ping/TOKEN". The && ensures curl only runs if script.sh succeeds.
How do I send additional information?
Use curl with data: curl -X POST -d "duration=120&status=ok" URL. MoniTao records these metrics.
Ready to Sleep Soundly?
Start free, no credit card required.