I'm searching for a reliable way to test if postfix is running from inside a bash script.
My first attempt was simply trying pidof postfix, which doesn't work.
Then I tried to get the 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
But even though the status is reported to the console, the result variable stays empty.
This is the console output:
postfix/postfix-script: the Postfix mail system is running: PID: 11996
Error: No status output from postfix
I finally found a way to test if postfix is running by getting the process name of PID: 11996, which is "master". So the following does work:
pidof master
But this is not very verbose and I'm not sure if this is a reliable way to test if postfix is running.
So my questions are:
- How can I get the output of
postfix statusfrom inside a bash script? - Anything I'm doing wrong there? - Is there a better reliable way to test if
postfixis running from inside a bash script?