4

I need to execute a command with a timeout in OpenWRT, but it seems that the command timeout is not installed by default neither can be installed using opkg. I know that I can do a work around (using command &; sleep $DELAY; kill $!), but I wish to do this more properly without getting the risk of kill trying to kill a process in case the command finished before the timeout.

Gabriel Diego
  • 950
  • 2
  • 10
  • 22

3 Answers3

8

Yes you can install timeout on openWRT

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

This has been tested with AA, pretty sure that would also work with BB.

Noel
  • 3,749
  • 3
  • 22
  • 21
1

In short: it is not possible. I have to do it using sleep && kill.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Gabriel Diego
  • 950
  • 2
  • 10
  • 22
0

timeout is a shell command so it executes in a subshell

timeout 6 sleep 20 will work if executed in direct shell terminal but same command won't work if initiated from a shell script.

So to run timeout in a shell script , use like this out="$(timeout 6 sleep 20)" OR echo "$(timeout 10 sleep 20)"

this will run your timeout and your command in one subshell

diveinsky
  • 165
  • 2
  • 8
  • Thank you for the answer, but I don't have the router anymore. I remember looking into the opkg repository and the timeout package was not there. I'm not sure why, maybe it was the architecture that was limited so they left this package out. – Gabriel Diego May 20 '16 at 21:37
  • ok...and you can compile timeout's source code with openwrt sdk – diveinsky May 24 '16 at 07:55