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