是否可以在 OpenWRT 中安装超时

Is it possible to install timeout in OpenWRT

我需要在OpenWRT中执行超时命令,但默认情况下似乎没有安装命令超时,也无法使用opkg安装。我知道我可以解决这个问题(使用命令 &; sleep $DELAY; kill $!),但我希望更正确地执行此操作,而不会因为命令在超时前完成而导致 kill 试图终止进程的风险.

简而言之:这是不可能的。我必须使用 sleep && kill.

是的,你可以在openWRT上安装timeout

$ opkg update
$ opkg install coreutils-timeout
$ timeout 2 sleep 10

这已经用 AA 测试过,很确定它也适用于 BB。

timeout 是一个 shell 命令,因此它在子 shell

中执行 如果在直接 shell 终端中执行,

timeout 6 sleep 20 将起作用,但如果从 shell 脚本启动,相同的命令将不起作用。

所以要在 shell 脚本中 运行 超时,像这样使用 out="$(timeout 6 sleep 20)" 要么 echo "$(timeout 10 sleep 20)"

这将 运行 你的超时和你的命令在一个子shell