Which exit status should a deployment‑check script treat as success when grep finds no matches?
0 reputation · 16 Jan 2023, 06:15 UTC
Goal
Diagnose a failed deployment by inspecting application logs with a Bash script that uses grep and head pipelines.
Constraints
The script runs with set -e and set -o pipefail to abort on errors, but grep returns 1 when no lines match, 2 on file errors, and 141 when terminated by SIGPIPE from head. These statuses are not automatically distinguishable by default.
Unresolved Decision
When the log contains no error lines, should the script consider grep’s exit 1 as a successful “no errors found” state, or as a distinct “log inconclusive” condition that warrants further investigation?
Specific Questions
- Should the script treat
grepexit 1 as a success or as an inconclusive state whenset -eandpipefailare enabled? - How can a Bash script reliably differentiate between
grepexit 1 (no match), exit 2 (file error), and the 141 SIGPIPE status produced byheadin a pipeline? - What best‑practice pattern should be used to combine
grepandheadin a diagnostic pipeline while preserving the correct exit status for each failure mode?