Cron Job Exit Codes: What 1, 2, 126, 127, 137, and 143 Mean
Contents
An exit code is the number a job's process returns when it ends: 0 means success, 1 to 125 are the program's own failure codes, 126 and 127 mean the command couldn't be run or found, and 128 plus a number means the process was killed by that signal, such as 137 for SIGKILL and 143 for SIGTERM. Cron runs the command and discards the code; it only mails any output. Kubernetes, systemd, and Windows Task Scheduler record it, but none of them alerts on it without help.
This reference covers Bash and POSIX shells, GNU coreutils timeout, cronie and Debian cron, Kubernetes, systemd, and Windows Task Scheduler, checked November 16, 2026. For writing scripts that return honest codes, see cron shell script best practices.
The Codes You'll See#
| Code | Meaning | Usual cause in a scheduled job |
|---|---|---|
| 0 | Success | The job finished, or claims to have |
| 1 | General failure | Any error the program didn't classify |
| 2 | Misuse, or a program-specific error | Bad arguments; Bash builtin misuse; grep hitting an error |
| 64–78 | BSD sysexits.h codes, by convention |
EX_USAGE (64), EX_TEMPFAIL (75), EX_CONFIG (78) |
| 124 | timeout stopped the command |
The job ran past its limit |
| 126 | Found but not executable | Missing execute bit, noexec mount |
| 127 | Command not found | Cron's minimal PATH, a typo, a missing package |
| 128 + n | Killed by signal n | See the signal table below |
| 255 | Often "exit -1", or ssh failing to connect |
exit -1 wraps to 255 |
Exit statuses are 8 bits, so the value wraps: exit 256 is 0 and exit -1 is 255. A program that returns a count of failed items as its exit code reports success when exactly 256 items fail. Return 1 and print the count instead.
1 and 2: The Program's Own Codes#
Anything from 1 to 125 is the program's choice, and its man page is the only authority. Conventions exist but conflict: Bash returns 2 for incorrect use of a builtin, grep returns 1 for "no lines matched" and 2 for an error, and diff returns 1 when the files differ. A job that runs grep -q ERROR app.log as a check fails with 1 on a clean log, which is often the opposite of what the author meant.
For your own scripts, pick a few distinct codes and document them: 1 for failure, 2 for bad configuration, 75 for "temporary, retry later." Distinct codes let a scheduler react differently, as Kubernetes podFailurePolicy can, and make an alert's message useful.
126 and 127: The Command Never Ran#
The shell returns 127 when it can't find the command and 126 when it found something it can't execute. For cron, 127 is the classic first-run failure: the job works in your terminal and fails under cron because cron's PATH is short, typically /usr/bin:/bin, and the tool lives in /usr/local/bin or a language version manager's shims. Use absolute paths, or set PATH= at the top of the crontab.
126 usually means the script lost its execute bit in a deploy or lives on a filesystem mounted noexec. A shebang can fail too: #!/usr/bin/env python on a host with only python3 makes env exit 127. Crontab errors covers what cron reports when the line itself is wrong.
128 + n: Killed by a Signal#
When a command terminates on a fatal signal number n, the shell reports 128 + n:
| Code | Signal | Who usually sends it |
|---|---|---|
| 129 | SIGHUP (1) | A closed terminal or session |
| 130 | SIGINT (2) | Ctrl-C in a terminal; rare under cron |
| 134 | SIGABRT (6) | The program aborted itself: a failed assertion, a runtime crash |
| 137 | SIGKILL (9) | The kernel OOM killer, kill -9, timeout -s KILL, or an orchestrator after its grace period |
| 139 | SIGSEGV (11) | A segmentation fault |
| 143 | SIGTERM (15) | A polite stop: systemctl stop, Kubernetes Pod termination, timeout --preserve-status |
137 deserves care, because it has many senders. On a host, check the kernel log for the OOM killer (journalctl -k | grep -i 'out of memory'). In Kubernetes, the container's last state says OOMKilled when the memory limit was the cause. Otherwise something sent SIGKILL on purpose, often after SIGTERM was ignored. 143 means the job was asked to stop and did, which during a deploy or node drain is expected but still means the run didn't finish.
To turn a code back into a signal name in a script, subtract 128 and ask the shell: kill -l 9 prints KILL.
Cron Itself Ignores the Code#
cron starts the command, waits for it, and mails anything it wrote to stdout or stderr to the crontab's owner or MAILTO. The exit code changes nothing: a job that exits 1 silently sends no mail, and a job that prints a progress line and exits 0 sends mail every night. Without a mail transport, even that output is dropped, as cron "No MTA installed" explains.
Debian's cron can log failures. Its -L option takes a sum of flags, where 4 "will log all failed jobs (exit status != 0)"; the default is 1, which logs only job starts (cron(8)). Options for the daemon go in /etc/default/cron. cronie logs a line per job start, not the result. Either way, the log is a record, not an alert.
Pipelines, set -e, and pipefail#
A script's exit code is the status of the last command it ran, unless it calls exit. Two shell rules hide failures:
- A pipeline's status is its last command's.
pg_dump app | gzip > app.sql.gzexits 0 whenpg_dumpfails, becausegzipsucceeded at compressing nothing.set -o pipefail(Bash, ksh, and zsh; added to POSIX in its 2024 edition, so check your/bin/sh) makes the pipeline fail if any command in it fails. In Bash,${PIPESTATUS[@]}holds each command's status. - A script continues after a failed command unless it uses
set -e, andset -edoesn't apply in conditions,&&/||lists, or (in Bash) command substitutions in many contexts.
#!/bin/bash
set -euo pipefail
pg_dump --format=custom app | gzip > "/backups/app-$(date +%F).dump.gz"Cron shell script best practices covers where set -e doesn't reach and how to trap cleanup.
timeout: 124 and Friends#
GNU timeout runs a command with a time limit and has its own codes (timeout(1)):
| Code | Meaning |
|---|---|
| 124 | The command timed out (and --preserve-status wasn't given) |
| 125 | timeout itself failed, such as a bad duration |
| 126 | The command was found but couldn't be invoked |
| 127 | The command wasn't found |
| 137 | The command, or timeout, was sent SIGKILL |
Without -s, timeout sends SIGTERM; -k 30s adds a SIGKILL 30 seconds later if the command is still running. With --preserve-status, a job that exits on SIGTERM returns 143 instead of 124. Pick one and handle it, so an alert can say "timed out" rather than "failed":
timeout -k 30s 2h /opt/app/nightly-importCron job timeouts covers choosing the limit.
How Other Schedulers Show the Code#
Kubernetes#
A container's exit code is in the Pod's status: state.terminated for the current container, lastState.terminated after a restart under restartPolicy: OnFailure. The reason is Completed, Error, or OOMKilled:
kubectl get pod nightly-import-29384955-x7k2p -o jsonpath=\
'{range .status.containerStatuses[*]}{.name} exit={.state.terminated.exitCode} reason={.state.terminated.reason} last={.lastState.terminated.exitCode}{"\n"}{end}'A non-zero code is a failed attempt that counts toward the Job's backoffLimit, and with restartPolicy: Never a podFailurePolicy rule can fail the Job at once on a specific code. Kubernetes CronJob failure handling shows how.
systemd#
systemd records the main process's code and turns it into a result:
systemctl show nightly-import.service -p Result -p ExecMainCode -p ExecMainStatusResult is exit-code for a non-zero exit, signal or core-dump for a kill, oom-kill for the OOM killer, and timeout when TimeoutStartSec= stopped it. ExecMainStatus is the number. ExecStopPost= commands receive the same facts as $SERVICE_RESULT, $EXIT_CODE, and $EXIT_STATUS, and SuccessExitStatus= lets you declare extra codes as success. systemd also defines its own codes from 200 upward for setup failures before your program ran, such as 203 (EXIT_EXEC) when the executable can't be started (systemd.exec(5)). systemd OnFailure alerts covers acting on them.
Windows Task Scheduler#
The task's Last Run Result shows the code in hexadecimal: 0x0 for success, 0x1 for exit code 1. Some values are Task Scheduler's own status rather than your program's: 0x41301 means the task is currently running and 0x41303 that it hasn't run yet. In the task's History tab, the "Action completed" event includes the action's return code. Windows Task Scheduler monitoring covers the rest.
Put the Code in the Failure Alert#
The exit code is the cheapest diagnostic a job has, and most setups throw it away. Capture it right after the job runs, before any other command overwrites $?, and send it with the failure report:
#!/bin/sh
# /opt/app/nightly-import-monitored: run the import and report its result to CronRadar.
CRONRADAR_API_KEY=$(cat /etc/cronradar/api-key 2>/dev/null)
run_id="nightly-import-$(date +%s)-$$"
report() {
event=$1
shift
curl --fail --silent --show-error --max-time 5 --output /dev/null \
--request POST --get --user "$CRONRADAR_API_KEY:" \
--data-urlencode "schedule=0 3 * * *" \
--data-urlencode "run_id=$run_id" \
"$@" "https://cron.life/api/v1/ping/nightly-import/$event" || true
}
report start
timeout -k 30s 2h /opt/app/nightly-import
rc=$?
case $rc in
0) reason="" ;;
124) reason="timed out after 2h" ;;
126) reason="not executable" ;;
127) reason="command not found" ;;
*) if [ "$rc" -gt 128 ]; then
reason="killed by SIG$(kill -l $((rc - 128)))"
else
reason="failed"
fi ;;
esac
if [ "$rc" -eq 0 ]; then
report complete
else
report fail --data-urlencode "message=nightly-import exit $rc: $reason"
fi
exit "$rc"The script exits with the job's own code, so cron, a parent script, or anything else that checks it sees the real result. Each report gives up after five seconds and ignores errors. Keep message short, at most 1,000 characters, and never put logs, secrets, or customer data in it.
With CronRadar, a fail report alerts immediately by email, Slack, webhook, Discord, or PagerDuty, with that message attached. A job that never starts, or is killed before it can report, sends no outcome: after the expected time plus the grace period, the monitor goes from warning to critical, and a start with no finish is flagged as stuck. There's no CronRadar package for crontab, so each job reports over HTTP like this. Inside a framework, the Laravel, Celery, Hangfire, and Quartz.NET integrations report failures from the scheduler without a wrapper, and the base SDKs for Python, Node.js, PHP, and .NET record a failure when the wrapped function throws, then re-throw it.
Frequently Asked Questions#
What does exit code 137 mean?#
The process was killed by SIGKILL (128 + 9). The usual senders are the kernel's OOM killer, Kubernetes enforcing a memory limit (the container shows OOMKilled), timeout -s KILL, or a supervisor that sent SIGKILL after SIGTERM was ignored. Check the kernel log or the container's last state to tell which.
What does exit code 127 mean in cron?#
The shell couldn't find the command. Under cron that's usually the short default PATH, so a tool in /usr/local/bin or a version manager's directory isn't found. Use the command's absolute path or set PATH= in the crontab.
Does cron do anything with a job's exit code?#
No. cron mails the job's output, if there is any and a mail transport works, and ignores the exit code. Debian's cron can log failed jobs with -L 4, but nothing alerts.
What is exit code 143?#
The process exited on SIGTERM (128 + 15), the signal used for a graceful stop by systemctl stop, Kubernetes Pod termination, and timeout --preserve-status. The job was stopped, not crashed, but the run didn't finish.
Why does my script exit 0 when a command failed?#
Its exit code is the last command's, so a failure followed by a successful command, or a failing command early in a pipeline, is hidden. Use set -e and set -o pipefail, or capture each important status and exit with it.
Put this guide to work
Know when the next run is missing
Connect one scheduled job, confirm a real completion, then verify the alert destination. Keep your existing scheduler in charge of running the work.