Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 339

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 392

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 394
linux 单例运行脚本 crontab 不需要调整代码即可实现 - Joyber 的博客

直接在crontab列表执行的时候加上判断,不需要修改任何代码
直接上代码吧

*/1 * * * * if [ `ps aux| grep weixinmsgtask | grep -v grep | wc -l` -lt 1 ]; then echo 1111; /web/xxx/protected/yiic weixinmsgtask send >> /web/xxx/protected/runtime/weixinmsgtask.log 2>&1; else echo 22222; fi

原理很简单,就是先判断一下有没有脚本正在运行,如果没有则运行起来,有的话就不做任何操作
代码中的 echo 111,2222 这个是为了测试添加的可以去掉
这个例子真要要执行的脚本是这个,你替换成你自己要执行的命令,以及把 weixinmsgtask 这个关键词替换成 你的命令中的关键词,大功告成

/web/xxx/protected/yiic weixinmsgtask send >> /web/xxx/protected/runtime/weixinmsgtask.log 2>&1

标签: linux

添加新评论