如果停止使用Cron,如何启动应用程序?

时间:2016-12-12 19:43:14

标签: linux bash cron

Debian 8.6。没有根。
我可以用cron 我需要检查在后台运行的应用程序(php ./somescript& amp;)是否已停止,然后重新启动它。如何使用bash进行检查?
当然,还有ps aux | grep .....,但我如何实现自动化呢?

2 个答案:

答案 0 :(得分:0)

一种方法是:

的Cron:

* * * * * env DISPLAY=:0 /folder/myscript >/dev/null 2>&1

您的情况可能不需要env DISPLAY=:0,或者可能需要echo $DISPLAY,具体取决于您的脚本(注意:您可能需要根据您的情况进行调整,运行#!/bin/bash testvar="$(ps aux | grep -s "somescript" | grep -sv "grep")" if [ -z "$testvar" ]; then nohup /folder/somescript &; fi exit 0 以查找您的案件的变量)。

脚本:

| grep -sv "grep"

这一切都可以而且应该根据您的需求进行调整,但我相信这个例子可以很好地为您服务。

修改:我对代码进行了一次小的疏忽(我添加了tesvar以摆脱从curl "https://www.instagram.com/explore/tags/plebiscito/" --http1.1 -k "https://www.instagram.com/query/" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d "q=ig_hashtag(plebiscito)+{+media.after(j0hwe66aaaaaf0hwexjmwaaafkwa,+12)+{++count,++nodes+{++++caption,++++code,++++comments+{++++++count++++},++++comments_disabled,++++date,++++dimensions+{++++++height,++++++width++++},++++display_src,++++id,++++is_video,++++likes+{++++++count++++},++++owner+{++++++id++++},++++thumbnail_src,++++video_views++},++page_info}+}&ref=tags::show&query_id=/" --next --http1.1 -k "https://www.instagram.com/ajax/bz" -H "Content-Type: application/json" -X POST -d '{"q":[{"page_id":"7mj51x","posts":[["timespent_bit_array",{"tos_id":"7mj51x","start_time":1481556875,"tos_array":[3,0],"tos_len":2,"tos_seq":2,"tos_cum":19,"log_time":1481556876912},1481556876912,0]],"trigger":"timespent_bit_array"}],"ts":1481556877336}' --next -k "https://www.instagram.com/query/" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d "q=ig_hashtag(plebiscito)+{+media.after(j0hwe66aaaaaf0hwexjmwaaafkwa,+8)+{++count,++nodes+{++++caption,++++code,++++comments+{++++++count++++},++++comments_disabled,++++date,++++dimensions+{++++++height,++++++width++++},++++display_src,++++id,++++is_video,++++likes+{++++++count++++},++++owner+{++++++id++++},++++thumbnail_src,++++video_views++},++page_info}+}&ref=tags::show&query_id=/" --next -k "https://www.instagram.com/ajax/bz" -H "Content-Type: application/json" -X POST -d '{"q":[{"page_id":"7mj51x","posts":[["timespent_bit_array",{"tos_id":"7mj51x","start_time":1481556875,"tos_array":[3,0],"tos_len":2,"tos_seq":2,"tos_cum":19,"log_time":1481556876912},1481556876912,0]],"trigger":"timespent_bit_array"}],"ts":1481556877336}' 结果中查找文件的grep进程

答案 1 :(得分:0)

我建议您从@reboot查看关键字man 5 crontab,以便在服务器启动时启动作业。