Bash if command doesn't finish in X time?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I'm trying to run something like:
sudo dhclient $wifi || otherFunction
Problem is when dhclient
fails it just hangs instead of throwing an error.
How can I re-write the above so dhclient
is killed and otherFunction
gets called if dhclient
doesn't finish in 60 seconds?
bash timeout
add a comment |Â
up vote
4
down vote
favorite
I'm trying to run something like:
sudo dhclient $wifi || otherFunction
Problem is when dhclient
fails it just hangs instead of throwing an error.
How can I re-write the above so dhclient
is killed and otherFunction
gets called if dhclient
doesn't finish in 60 seconds?
bash timeout
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'm trying to run something like:
sudo dhclient $wifi || otherFunction
Problem is when dhclient
fails it just hangs instead of throwing an error.
How can I re-write the above so dhclient
is killed and otherFunction
gets called if dhclient
doesn't finish in 60 seconds?
bash timeout
I'm trying to run something like:
sudo dhclient $wifi || otherFunction
Problem is when dhclient
fails it just hangs instead of throwing an error.
How can I re-write the above so dhclient
is killed and otherFunction
gets called if dhclient
doesn't finish in 60 seconds?
bash timeout
asked Nov 17 '17 at 20:18
Philip Kirkbride
2,2922470
2,2922470
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
6
down vote
accepted
Your timeout tag gives it all away:
sudo timeout 60 dhclient $wifi || otherFunction
An example:
sudo timeout 3 sleep 5 || echo finished early
This uses the timeout utility provided by the GNU coreutils package on Linux.
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
2
down vote
Use timeout
.
timeout 2 sleep 1
echo $?
0
timeout 1 sleep 2
echo $?
124
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
1
down vote
Use the timeout
packed as gtimeout
with the coreutils
port in brew
:
brew install coreutils
gtimeout --help
That'll work with /usr/local/bin
in your PATH
. If you want to use timeout
as originally named, add /usr/local/opt/coreutils/libexec/gnubin
to your PATH
.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
Your timeout tag gives it all away:
sudo timeout 60 dhclient $wifi || otherFunction
An example:
sudo timeout 3 sleep 5 || echo finished early
This uses the timeout utility provided by the GNU coreutils package on Linux.
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
6
down vote
accepted
Your timeout tag gives it all away:
sudo timeout 60 dhclient $wifi || otherFunction
An example:
sudo timeout 3 sleep 5 || echo finished early
This uses the timeout utility provided by the GNU coreutils package on Linux.
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
Your timeout tag gives it all away:
sudo timeout 60 dhclient $wifi || otherFunction
An example:
sudo timeout 3 sleep 5 || echo finished early
This uses the timeout utility provided by the GNU coreutils package on Linux.
Your timeout tag gives it all away:
sudo timeout 60 dhclient $wifi || otherFunction
An example:
sudo timeout 3 sleep 5 || echo finished early
This uses the timeout utility provided by the GNU coreutils package on Linux.
answered Nov 17 '17 at 20:21
Jeff Schaller
32.1k849109
32.1k849109
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
2
down vote
Use timeout
.
timeout 2 sleep 1
echo $?
0
timeout 1 sleep 2
echo $?
124
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
2
down vote
Use timeout
.
timeout 2 sleep 1
echo $?
0
timeout 1 sleep 2
echo $?
124
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Use timeout
.
timeout 2 sleep 1
echo $?
0
timeout 1 sleep 2
echo $?
124
Use timeout
.
timeout 2 sleep 1
echo $?
0
timeout 1 sleep 2
echo $?
124
answered Nov 17 '17 at 20:22
Matt Clark
204211
204211
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
doesn't work on MacOS unfortunately
â Alexander Mills
Apr 20 at 22:13
add a comment |Â
up vote
1
down vote
Use the timeout
packed as gtimeout
with the coreutils
port in brew
:
brew install coreutils
gtimeout --help
That'll work with /usr/local/bin
in your PATH
. If you want to use timeout
as originally named, add /usr/local/opt/coreutils/libexec/gnubin
to your PATH
.
add a comment |Â
up vote
1
down vote
Use the timeout
packed as gtimeout
with the coreutils
port in brew
:
brew install coreutils
gtimeout --help
That'll work with /usr/local/bin
in your PATH
. If you want to use timeout
as originally named, add /usr/local/opt/coreutils/libexec/gnubin
to your PATH
.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Use the timeout
packed as gtimeout
with the coreutils
port in brew
:
brew install coreutils
gtimeout --help
That'll work with /usr/local/bin
in your PATH
. If you want to use timeout
as originally named, add /usr/local/opt/coreutils/libexec/gnubin
to your PATH
.
Use the timeout
packed as gtimeout
with the coreutils
port in brew
:
brew install coreutils
gtimeout --help
That'll work with /usr/local/bin
in your PATH
. If you want to use timeout
as originally named, add /usr/local/opt/coreutils/libexec/gnubin
to your PATH
.
answered Aug 16 at 1:21
Garth Kidd
1113
1113
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405337%2fbash-if-command-doesnt-finish-in-x-time%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password