crontab -e
20点59分启动脚本
59 20 * * * sh /home/fzuir/xingye4crawl/endXingYe4Crawl.sh >/home/fzuir/xingye4crawl/xingye4_pro_kill.log 2>&1
启动:
#!/bin/bash . /home/fzuir/.profile# JAVA export JAVA_HOME=/usr/local/jdk1.7.0_75 export JRE_HOME=$JAVA_HOME/jre export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar#hm=$(date +%H | awk '{print $0+0}') #echo $hm%3 #tmp=$(($hm%3))today=`date +%Y%m%d`; yesterday=`date -d '1 days ago' +%Y%m%d` echo yesterdayif [ -x /bin/ps ];then/bin/ps -ef >/tmp/Skycent$$$ 2>/tmp/Skycent.err$$$if [ $? -ne 0 ];thenexit 1fi/bin/rm -f /tmp/Skycent.err$$$ elseecho "PS Not Exist"exit 1 figrep "xingye4CrawlMainThread" /tmp/Skycent$$$ >/dev/null 2>/dev/nullif [ $? -ne 0 ];thencd /home/fzuir/xingye4crawl java -jar xingye4CrawlMainThread.jar ./conf/xinye4conf.properties >> ./nohup.out 2>&1 &else echo "xingye4CrawlMainThread.jar is already Runing " fi/bin/rm -f /tmp/Skycent$$$
结束进程:
#!/bin/bash . /home/fzuir/.profile ################################################ # 用于在零点时检测当前是否有抽取程序在运行,如果有则停止该程序 # 用法:将 用于识别程序名的关键词 按实际情况修改即可,需将本sh加入crontab在每天零点运行 # keys=`(ps -ef |grep 用于识别程序名的关键词 |grep -v grep) | awk '{print $2}'` ################################################ keys=`(ps -ef |grep xingye4CrawlMainThread |grep -v grep) | awk '{print $2}'` if [ $? -eq 0 ];thenecho "exist this process"for key in $keysdoecho $keykill -9 $keydone else echo "not exist this process" fi