自己写了一个shell脚本来定时执行重启项目的任务
单独运行shell脚本,但是使用crontab 定时执行时,shell脚本只执行前一部分,后一部分不执行
在网上找了很多方法,都没有解决,最后找到一个博主写的 文章找到了解决办法
链接为http://blog.csdn.net/song_0328/article/details/78037962
就是需要在shell脚本中加上这样一段
source /etc/profile
例如
#!/bin/bash#
source /etc/profile
#kill cf process
CF_RES=`ps -ef | grep java|grep 'XXXXX.jar' | wc -l`
CF_PID=`ps -ef | grep java|grep 'XXXXX.jar' | awk 'NR==1 {print $2}'`
if [ "$CF_RES" -gt "0" ]
then
echo $pid
kill -9 ${CF_PID}
echo "XXXXX process has been killed..."
cd "$RUN_HOME"/portal-scheduler
nohup java -jar XXXXX.jar >/dev/null 2>&1 &
else
cd "$RUN_HOME"/portal-scheduler
nohup java -jar /home/hhhh/XXXXX.jar >/dev/null 2>&1 &
fi
然后使用crontab -e 写定时任务
*/30 * * * * sh /home/hhh/demo.sh
这样就可正常执行了