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 status
from inside a bash script? - Anything I'm doing wrong there? - Is there a better reliable way to test if
postfix
is running from inside a bash script?
status
outputs tostderr
? Try to add2>&1
tostatus
-command. Also you can usepgrep postfix
– Costas Feb 28 '15 at 7:522>&1
but the result stays empty. Sadlypgrep
is no option because it is not available on the system (a Synology disk station with DSM 5.1). – Balder Feb 28 '15 at 8:05ps aux | grep [p]ostfix
? – Costas Feb 28 '15 at 8:41ps
seems to work. On the DSM systemps
doesn't accept any parameters other thenw
. But simply callingps | grep [p]ostfix
does work. – Balder Feb 28 '15 at 8:49