gpt4 book ai didi

Bash : If command timeout, 执行其他操作

转载 作者:行者123 更新时间:2023-12-01 01:16:03 25 4
gpt4 key购买 nike

我正在做以下事情:

timeout 180 bash myscript.txt

myscript.txt 应该在不到 180 秒的时间内完全执行。如果不是,我希望执行 emergencyscript.txt。是否可以这样做?

喜欢

timeout 180 [bash myscript.txt] [bash emergencyscript.txt]

最佳答案

如果命令超时,timeout 的退出状态为 124。您可以对此进行显式测试。

timeout 180 bash myscript.txt
exit_status=$?
if [[ $exit_status -eq 124 ]]; then
bash emergencyscript.txt
fi

exit_status 的任何其他值都是 myscript.txt 运行完成的结果。

关于Bash : If command timeout, 执行其他操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38534097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com