這個腳本總是返回「running」,這是否有任何理由,無論我的進程是啓動還是停止?if語句總是計算爲TRUE
if ps ax | grep -v grep | grep "processName" > /dev/null
then
echo $"running"
else
echo $"not running"
fi
非常感謝您
UPDATE: 添加我的劇本的一個完整的例子,也許還有其他地方的一些錯誤。
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
更新2:
[[email protected] init.d]# pgrep -f "MyProcess" > /dev/null
[[email protected] init.d]# echo $?
0
[[email protected] init.d]# service MyProcess stop
Shutting down MyProcess: Terminated
[[email protected] init.d]# pgrep -f "MyProcess" > /dev/null
[[email protected] init.d]# echo $?
1
但if [ $? -eq 0 ]; then
似乎是真實的
要回答你的問題,是的。 ;-) – 2009-11-11 14:05:37
@Mike,當你將輸出重定向移除到/ dev/null時,你會看到什麼?事實上,你的流程或其他類似的名稱正在運行嗎? – pilcrow 2009-11-11 14:44:59
@pilcrow,當我的過程開始時,我看到了過程的結果,當過程停止時,我看不到任何結果。 – Mike 2009-11-11 14:53:16