apachectl catch or suppress configtest's "Syntax OK"
Apache's configtest
is useful to catch syntax errors. On success it prints "Syntax OK" and when running apachectl configtest
in a bash script I want to suppress this.
I have tried the usual output redirections to /dev/null
, assigning the results to a variable like so:
AOUTPUT=$(/usr/sbin/apache2ctl -t && /usr/sbin/apache2ctl graceful)
but "Syntax OK" is always output.
Can this be suppressed?
Solution 1:
Inside $()
you can still redirect stderr to be the same as stdout, and then it will be captured by the assignment. For example:
if AOUTPUT=$(/usr/sbin/apache2ctl -t 2>&1)
then /usr/sbin/apache2ctl graceful
else rc=$?; printf "%s\n" "$AOUTPUT" >&2; exit $rc
fi
I added the >&2
so the errors still come out on stderr, and the exit
to try to duplicate the original error code from the command, but you would only really need them if you were putting this in a shell script and wanted to preserve those features.