Is there any reason why this script always returns "running", regardless of whether my process is started or stopped?
if ps ax | grep -v grep | grep "processName" > /dev/null
then
echo $"running"
else
echo $"not running"
fi
Thank you very much
UPDATE : I add a full example of my script, maybe there is something wrong elsewhere.
case "$1" in
start)
# Start daemons.
echo -n $"Starting daemon: "
;;
stop)
# Stop daemons.
echo -n $"Shutting down: "
echo
;;
status)
pgrep -f "ProcessName" > /dev/null
if [ $? -eq 0 ]; then
echo $"ProcessName is running"
else
echo $"ProcessName is not running"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
UPDATE 2 :
[user@dev init.d]# pgrep -f "MyProcess" > /dev/null
[user@dev init.d]# echo $?
0
[user@dev init.d]# service MyProcess stop
Shutting down MyProcess: Terminated
[user@dev init.d]# pgrep -f "MyProcess" > /dev/null
[user@dev init.d]# echo $?
1
But if [ $? -eq 0 ]; then
seems to be TRUE all the time