Is there an alternative for the timeout command on Mac OSx. The basic requirement is I am able to run a command for a specified amount of time.
e.g:
timeout 10 ping google.com
This program runs ping for 10s on Linux.
Is there an alternative for the timeout command on Mac OSx. The basic requirement is I am able to run a command for a specified amount of time.
e.g:
timeout 10 ping google.com
This program runs ping for 10s on Linux.
The Timeout Package from Ubuntu / Debian can be made to compile on Mac and it works. The package is available at http://packages.ubuntu.com/lucid/timeout
Another simple approach that works pretty much cross platform (because it uses perl which is nearly everywhere) is this:
Snagged from here: https://gist.github.com/jaytaylor/6527607
Instead of putting it in a function, you can just put the following line in a script, and it'll work too:
timeout.sh
or a version that has built in help/examples:
timeout.sh
You can use
And then whenever you need timeout, use
..instead. To explain why here's a snippet from the Homebrew Caveats section:
Unfortunately there is no timeout program on macos afaik, however you can try the answers metioned here: Command line command to auto-kill a command after a certain amount of time
Futhermore if you really want to run "ping" here you can just run
You can limit execution time of any program using this command: