作者:菲菲鱼2009 | 来源:互联网 | 2023-01-31 16:36
我想在bash脚本中执行一个大约需要1分钟才能完成的命令.但是,有时这个命令会挂起,所以我想在循环中使用/ usr/bin/timeout直到它工作.
如果我使用timeout 300 mycommand myarg1
它,它可以工作,但如果我在下面的循环中使用它在bash中,它不打印任何东西(甚至不是我的命令打印的典型输出)并且它挂起!:
until timeout 300 mycommand myarg
do
echo "The command timed out, trying again..."
done
我的bash版本:
$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
我的超时版本:
$ timeout --version
timeout (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
(标准Ubuntu16.04)