用shell脚本守护后台进程

假如现在在 crond 中添加了一个每分钟执行的定时任务如下:

*/1 * * * * root cd /data/sbin; sh test.sh >/dev/null 2>&1

为了防止上一个进程还没完成,下一个进程就启动,我们可以创建一个shell来守护该进程,方法如下:

#!/bin/sh
ps aux | grep test/init | grep -v  grep > /dev/null

if [ $? != 0 ]
then
    echo "Yii test not runing"
    cd /data/web/; /usr/bin/php yii test/init 1>/dev/null 2>/tmp/test.txt &
fi

猜你喜欢

转载自www.cnblogs.com/chrdai/p/9244706.html