大网数据广告活动
服务器运维问答

apachectl catch or suppress configtest's "Syntax OK"

· 52CE 我爱测

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 , assi…

问题原文

原帖链接 · PeterB · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · meuh · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。