Is there any reason this script always give me running ? In both cases, when my process is started and when my process is 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 exemple of my script, maybe smothing wrong somewhere else.
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 always be true