今天第二段shell脚本
停止运行的Java爬虫
spiderPID=0
for spider in spider141212Run spider141205Run spider141213Run spider141204Run
do echo 'stop crawler' $spider $te;
ps=`ps -ef | grep $spider | grep -v grep`
if [ -n "$ps" ]; then
#echo "PID" $ps
spiderPID=`echo $ps | awk '{print $2}'` ;
echo "spiderPID: " $spiderPID ;
kill $spiderPID
else
echo $spider' stoped'
fi
done
一开始报错:
./stopSpider.sh: line 9: ps -ef | grep bucket141213Run | grep -v grep: command not found
后来发现是
ps=ps -ef | grep $spider | grep -v grep
ps=ps -ef | grep $spider | grep -v grep
注意命令不是单引号,而是esc 键附近的波折号。
有问题,注意输入法,报错的话重新写一遍此命令。