如何检查立即上一次运行是否失败? [英] How to check if immediate previous run failed or not?

查看:56
本文介绍了如何检查立即上一次运行是否失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行的perl脚本,并进行了一些检查.
在某些情况下,脚本会失败并停止处理,而在另一些情况下,脚本会完成.
我想做的是能够检查脚本是否在1分钟内运行,以及运行是否成功,然后退出.
我考虑过保存一些文件或检查$?作为指示,但我认为可能存在一些标准的清除方法.
想要一个适用于linux和mac的解决方案

I have a perl script that runs and does some checks.
In some cases that script fails and stops processing and in others completes.
What I would like to do is to be able to check if the script run within 1 minute and if the run was successful somehow then exit.
I thought about saving some file or checking $?, as an indication but I thought there may be exist some standard clean approach for this.
Would like a solution that would work for both linux and mac

推荐答案

您可以通过尝试如下操作来查看脚本是否在一分钟后结束:

You could see if you script has ended after a minute by trying something like this :

sleep 60
ps -ae | grep yourScript.name

此操作必须与您的脚本同时执行.如果未返回任何内容,则意味着您的脚本不再运行,又名已结束.

This has to be executed at the same time as your script(s). If it returns nothing, that means your script isn't running anymore, aka has ended.

要获得最终结果,可以使您的perl脚本写入特定的日志文件,并检查 ps -ae |日志文件的末尾.grep yourScript.name 不返回任何内容.

For the final result, you could make your perl script write into a specific log file, and check the end of this log file if the ps -ae | grep yourScript.name returned nothing.

希望对您有所帮助!

这篇关于如何检查立即上一次运行是否失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆