我正在寻找一种可靠的方法来测试是否postfix从 bash 脚本内部运行。
我的第一次尝试只是尝试pidof postfix,这是行不通的。
然后我试图得到postfix status:
POSTFIX_LOCATION=/var/packages/MailServer/target/sbin/postfix # location of postfix
result=`$POSTFIX_LOCATION status`
if [ -z $result ]; then
echo "Error: No status output from postfix"
elif [[ "$result" == *"is running"* ]]; then
echo "postfix is running!"
else echo "postfix is not running!"
fi
Run Code Online (Sandbox Code Playgroud)
但即使状态报告给控制台,该result变量仍为空。这是控制台输出:
postfix/postfix-script: the Postfix mail system is running: PID: 11996
Error: No status output from postfix
Run Code Online (Sandbox Code Playgroud)
我终于找到了一种通过获取进程名称来测试 postfix 是否正在运行的方法PID: 11996,即“master”。所以以下确实有效:
pidof master …Run Code Online (Sandbox Code Playgroud)