Automation, Orchestration, and Scripting

A monitoring script must run its alert function when /var/log/app.log contains the string ERROR. The script must not print any matching lines. Which if statement is correct?

Show the answer

Correct answerD. if grep -q ERROR /var/log/app.log; then alert; fi

The if statement tests the exit status of a command directly, and grep -q returns 0 on a match without printing. Wrapping grep in command substitution inside brackets is tempting, but -q produces no output, so the string is always empty and the test is always false.