简体   繁体   English

如果一个Cron作业失败,请继续执行下一个作业

[英]If one Cron Job fails, carry on to next job

I've set up my Crontab to execute a selection of Python scripts in order to interrogate a solar inverter and upload the results to PVOutput: 我已经设置了Crontab来执行一系列Python脚本,以便查询太阳能逆变器并将结果上传到PVOutput:

*/5 * * * * cd /home/Pi/; python pvout_upload.py;
*/5 * * * * cd /home/Pi/; python weather.py;

The problem is if the internet goes down, then those scripts fail. 问题是,如果Internet断开,则这些脚本将失败。 So I've created another script that reads the inverter and stores the result to a local database that can be uploaded later. 因此,我创建了另一个脚本,该脚本读取逆变器并将结果存储到本地数据库中,以后可以上载。 But if there's no internet, then those previous Cron-task fail and the Python script won't run either. 但是,如果没有互联网,那么以前的Cron任务就会失败,并且Python脚本也不会运行。

Is there a way to have Cron-task carry on to the next line if one fails? 如果发生故障,是否有办法让Cron任务继续进行到下一行?

You can use classical shell resources for this. 您可以为此使用经典的shell资源。 If you put 如果你把

command1 || command2 

in your crontab line. 在您的crontab行中。 Then: 然后:

command2 will be executed if command1 fails (returns an error) It would be something like: 如果command1失败(返回错误),则将执行command2。

*/5 * * * * cd /home/Pi/; python pvout_upload.py || python errorManagement.py

Of course, you could also embed this logic in your python script. 当然,您也可以将此逻辑嵌入到python脚本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM