Get a Telegram Alert the Moment a Bash Script Fails

Tutorial · 2026-12-14 · 7 min read

An alert that lands in a mailbox is an alert that arrives too late. Telegram puts the notification where you already look — your phone — within seconds of a job going quiet.

This guide wires up the full path: create a bot, get your chat ID, and connect a cron job so that a stopped backup becomes a message on your phone.

Step 1 — Create the bot

Open Telegram, message @BotFather, and send /newbot. Pick a name and a username ending in bot. BotFather replies with a token that looks like 123456:ABC-DEF.... Treat it like a password.

Step 2 — Get your chat ID

Message @userinfobot any message. It replies with your numeric chat ID. Send one message to your new bot as well — bots cannot initiate a conversation with someone who has never messaged them.

Step 3 — Send a test message

With token and chat ID in hand, a direct API call verifies the whole path:

curl -s -X POST \
  "https://api.telegram.org/bot<TOKEN>/sendMessage" \
  -d chat_id="<CHAT_ID>" \
  -d text="TickAlive test: Telegram channel works"

If the message appears, the notification channel is good. Everything after this point is about deciding when to send it.

Step 4 — Alert on silence, not on error

You can make a script push a message when it fails, but that misses the case where the script never runs. The stronger pattern is the heartbeat: the job reports success, and a separate watcher sends the Telegram alert when a report is overdue.

With TickAlive, you paste the token and chat ID into the settings page once. The scheduler then owns the alerting logic — including the recovery message when a job starts checking in again.

Step 5 — Do not bury the alert

Put the bot in a group with the people who care about the job, not in a one-to-one chat only you read. A heartbeat alert that nobody else sees is a single point of failure — the same problem the job itself had.

Chinese teams often prefer WeCom (Enterprise WeChat) group robots. The setup is even simpler: add a bot to a group and paste its webhook URL. TickAlive supports both channels at once.

Test the whole loop

  1. Run the job once by hand — the dashboard should show it healthy.
  2. Set a short period and grace for testing (1 minute, 0 slack).
  3. Stop the job and wait. The Telegram alert should arrive on schedule.
  4. Restart it — a recovery message should follow.

If all four steps pass, the loop is proven end to end. For the reasoning behind heartbeat monitoring, see why cron jobs fail silently.

Know the moment a job stops

TickAlive is a self-hosted dead-man's switch for cron jobs. One curl line to plug in — Telegram or WeCom alerts when a job goes quiet.

Get TickAlive — $19
telegrambashalerts
← All articles Next article →