Fix pipefail race condition: Add || true to grep display lines
CRITICAL FIXES: - Line 63 (Exim): Added || true to frozen message display - Line 102 (Postfix): Added || true to suspended message display - Line 142 (Sendmail): Added || true to deferred message display WHY THIS MATTERS: With set -o pipefail enabled, if grep returns no matches (exit code 1), the script exits instead of continuing. This happens when: - Messages are counted and confirmed present (lines 60, 97, 137) - But queue changes before display (race condition) - grep finds no matches and returns 1 - Pipeline fails and script exits abnormally SOLUTION: Added || true to prevent script failure if messages disappear between check and display. Script now continues gracefully with no messages shown instead of terminating unexpectedly. TESTING: ✅ Syntax validation: PASS ✅ All three grep display lines protected ✅ Script continues if queue changes mid-execution
This commit is contained in:
@@ -60,7 +60,7 @@ if [ "$MTA" = "exim" ]; then
|
||||
frozen=$(eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep -c "^\[frozen\]" 2>/dev/null || true)
|
||||
if [ "$frozen" -gt 0 ]; then
|
||||
print_warning "$frozen frozen messages found"
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep "^\[frozen\]" | head -10
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep "^\[frozen\]" | head -10 || true
|
||||
else
|
||||
print_success "No frozen messages"
|
||||
fi
|
||||
@@ -99,7 +99,7 @@ elif [ "$MTA" = "postfix" ]; then
|
||||
if [ "$suspended" -gt 0 ]; then
|
||||
print_warning "$suspended suspended messages found (delivery deferred)"
|
||||
# Show message ID and first line of suspension reason
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep -B1 "delivery temporarily suspended" | head -20
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep -B1 "delivery temporarily suspended" | head -20 || true
|
||||
else
|
||||
print_success "No suspended messages"
|
||||
fi
|
||||
@@ -139,7 +139,7 @@ elif [ "$MTA" = "sendmail" ]; then
|
||||
if [ "$deferred" -gt 0 ]; then
|
||||
print_warning "$deferred deferred messages found"
|
||||
# Show deferred message reasons (continuation lines starting with spaces and parenthesis)
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep "^[[:space:]]*(" | head -20
|
||||
eval "$SYS_MAIL_CMD_QUEUE_LIST" | grep "^[[:space:]]*(" | head -20 || true
|
||||
else
|
||||
print_success "No deferred messages"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user