A health-check wrapper reports `check failed: unknown exit code 124` for `timeout 20 ./check_db.sh`. What does 124 mean, and what else can `timeout` return?
BeginnerTroubleshootingTroubleshooting: strict mode, exit codes, pipelines and traps
Answer
Likely causes → GNU timeout returns 124 when the time limit expired and it sent the signal. The check is hanging (DNS, a DB connection with no client timeout, a lock), not failing.
Diagnose →
timeout 20 ./check_db.sh; echo "rc=$?"
timeout -v 20 ./check_db.sh # -v prints "timeout: sending signal TERM to command ..."
bash -x ./check_db.sh # see which step hangs
Codes to know: 124 timed out, 125 timeout itself failed, 126 command not executable, 127 command not found, 137 killed with -s KILL (or by --kill-after).
Fix → Map 124 to a meaningful state and add timeouts inside the check, so it fails fast with a reason:
timeout --kill-after=5 20 ./check_db.sh; rc=$?
case $rc in
0) state=OK ;; 124|137) state=CRITICAL; reason="check timed out after 20s" ;; *) state=CRITICAL ;;
esac
Inside: psql "connect_timeout=5 ...", curl --max-time 5.
Prevent → Every external call in a check has its own timeout, and the wrapper has an outer timeout --kill-after.
More on Troubleshooting: strict mode, exit codes, pipelines and traps
A script with `set -e` stops silently right after `((retries++))` on its first pass. No error message, exit code 1.Intermediate`notify.sh: line 9: SLACK_WEBHOOK: unbound variable` — but the webhook is meant to be optional.BeginnerOn a CentOS 7 / Amazon Linux 2 host, `deploy.sh "${extra_args[@]}"` fails with `extra_args[@]: unbound variable`. It works on your laptop.Advanced`local release=$(curl -fsS "$API/latest")` fails with a 503, yet the function happily continues and deploys an empty release name.IntermediateA check `procs=$(ps aux | grep -v grep | grep -c '[n]ginx: worker')` kills the script under `set -euo pipefail` whenever nginx is down, before the alert code runs.IntermediateA script that does `first=$(sort -u huge.txt | head -n 1)` exits with status 141 under `pipefail`, but only on large inputs.Advanced