简体   繁体   English

知道如何在 linux 和 shell 脚本中使用带条件的超时命令

[英]Any idea how i can use timeout command with condition in linux and shell script

aim working on some shell script, i would like to check the following command旨在处理一些 shell 脚本,我想检查以下命令

df -h df -h

if timeout more than 60 second then echo "error " else pass.如果超时超过 60 秒,则回显“错误”,否则通过。

so if this command will not responding for 1 minute then I will receive and error message, otherwise it will pass, any creative idea will be high apricated.因此,如果此命令在 1 分钟内没有响应,那么我将收到错误消息,否则它将通过,任何创意都将受到高度评价。

timeout 60 df -h > /dev/null && echo "PASS" || echo "PROBLEM"

Using timeout, if the command df -h doesn't execute within 60 seconds or errors, it will return a none 0 return code.使用超时,如果命令 df -h 在 60 秒内未执行或出错,它将返回 none 0 返回码。 If a none 0 return code is returned echo "PROBLEM" using the ||如果返回无 0 返回码,则使用 || 回显“问题” condition.健康)状况。

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

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