0
我有一個進程腳本,我希望它運行並停止(如果已經運行)一個bash腳本。我試過pkill -x test
,但它似乎並不奏效。在任何情況下,我相信我需要一個if
聲明,看看是否test.sh
正在運行..如何在init.d進程中運行並停止bash腳本?
編輯:在停止我加for i in
ps ax | grep'test'| AWK '{打印$ 1}' ; do kill -9 $i; done
,似乎修復它..需要做一些更多的測試
這裏是代碼:
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
# Source function library.
. /etc/init.d/functions
prog="test"
NEWLINE=$'\n'
start() {
STR=$"Starting $prog ${NEWLINE}"
echo "$STR"
/var/www/html/test.sh
# code to start app comes here
# example: daemon program_name &
}
stop() {
STR=$"Stopping $prog ${NEWLINE}"
echo "$STR"
pkill -x test
# code to stop app comes here
# example: killproc program_name
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
${0} stop
sleep 1
${0} start
;;
status)
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
什麼想法?
'test'與'test.sh'不完全匹配。 – 2014-11-04 20:46:49