---
title: "Ping CronMissed from a shell script with curl"
url: "https://cronmissed.com/snippets/shell.md"
canonical_url: "https://cronmissed.com/snippets/shell"
last_updated: "2026-10-22"
type: "how-to"
summary: "A shell wrapper that reports start, exit status and the end of the output to CronMissed with curl, with the flags that make a ping safe."
related: ["https://cronmissed.com/snippets.md", "https://cronmissed.com/guides/linux-crontab.md", "https://cronmissed.com/snippets/docker.md", "https://cronmissed.com/learn/exit-codes-and-failure-signals.md", "https://cronmissed.com/tools/snippet-builder.md"]
---

# Ping CronMissed from a shell script with curl

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

A shell wrapper that reports start, exit status and the end of the output to CronMissed with curl, with the flags that make a ping safe.

In a shell script, one curl line after the job is the whole integration. This wrapper adds the start ping, sends the exit status, attaches the end of the output and makes sure a lost ping never changes what the script returns.

## What should a shell job send?

- A request to `/start` before the work, so CronMissed can time the run and notice a job that never finishes.
- A request to the plain URL when the work succeeded, or to `/fail` when it did not. `/<exit status>` works too: 0 is a success and any other number is a failure.
- The end of the output in the request body, up to 100,000 bytes, so the alert shows the error without a trip to the server.

## What is the wrapper?

```
#!/usr/bin/env bash
set -uo pipefail
PING_URL="${CRONMISSED_PING_URL:?set CRONMISSED_PING_URL}"

ping() { curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null "$@" || true; }

ping "$PING_URL/start"
output=$(/usr/local/bin/job.sh 2>&1)
status=$?
printf '%s\n' "$output" | tail -c 100000 | ping --data-binary @- "$PING_URL/$status"
exit "$status"
```

Keep the ping URL in an environment variable or a secret store, never in a public repository: the URL is the check's only credential.

## What do the curl flags do?

- `-f` makes curl fail on an HTTP error status, `-sS` hides the progress meter but still prints errors.
- `--max-time 10` gives up after ten seconds so a slow network cannot hold the job.
- `--retry 5` retries on transient errors, and `--retry-connrefused` includes a refused connection among them.
- `|| true` keeps a failed ping from changing the script's own exit status.

The one-line form for a crontab is `command && curl -fsS --retry 5 <url>`. See the [crontab guide](https://cronmissed.com/guides/linux-crontab.md).

## Questions

### Why use HTTPS and not HTTP?

Plain HTTP requests are answered with a redirect to HTTPS, and a client that does not follow redirects loses the ping. Use the https:// address from the check page.

### Why tail the output?

A ping body keeps up to 100,000 bytes. Sending the end keeps the request small and holds the part of the log where the error usually is.

## Sources

- [curl manual](https://curl.se/docs/manpage.html), read 22 October 2026

## Related pages

- [Linux crontab](https://cronmissed.com/guides/linux-crontab.md)
- [Docker](https://cronmissed.com/snippets/docker.md)
- [Exit codes and failure signals](https://cronmissed.com/learn/exit-codes-and-failure-signals.md)
- [/tools/snippet-builder](https://cronmissed.com/tools/snippet-builder.md)

## Related

- [Ping snippets for 12 languages and tools](https://cronmissed.com/snippets.md)
- [Monitor Linux crontab jobs with curl](https://cronmissed.com/guides/linux-crontab.md)
- [Ping CronMissed from a Docker container](https://cronmissed.com/snippets/docker.md)
- [Exit codes and failure signals in cron jobs](https://cronmissed.com/learn/exit-codes-and-failure-signals.md)
- [Cron monitoring snippet builder](https://cronmissed.com/tools/snippet-builder.md)
