【Linux】crontab 定时启动sh
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 yesterday if [ -x /bin/ps ];then /bin/ps -ef >/tmp/Skycent$$$ 2>/tmp/Skycent.err$$$ if [ $? -ne 0 ];then exit 1 fi /bin/rm -f /tmp/Skycent.err$$$ else echo "PS Not Exist" exit 1 fi grep "xingye4CrawlMainThread" /tmp/Skycent$$$ >/dev/null 2>/dev/null if [ $? -ne 0 ];then cd /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 ];then echo "exist this process" for key in $keys do echo $key kill -9 $key done else echo "not exist this process" fi