* bash scripting..simple question
@ 2002-09-13 9:16 urgrue
2002-09-13 9:37 ` Carl
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: urgrue @ 2002-09-13 9:16 UTC (permalink / raw)
To: admin
is there a way, in a bash script, to do something like:
execute "this_command these_params"
--if-its-not-done-in-600-seconds-then-kill-it-and-return-an-error-code
situation is, i have a simple script that logs into remote boxes, and
does some checks.
it first pings each box to see if the route is up, if that fails it
wont even try to log in.
but sometimes, a box can be pinged but not logged into, for various
reasons.
in these cases, the ssh login attempt seems to just sit there and
doesnt timeout, and the whole script hangs, waiting until ssh exits.
which i have observed to take at times HOURS, at times it _never_ exits.
any suggestions?
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: bash scripting..simple question
2002-09-13 9:16 bash scripting..simple question urgrue
@ 2002-09-13 9:37 ` Carl
2002-09-13 9:51 ` Michael Salmon
2002-09-13 14:55 ` Glynn Clements
2 siblings, 0 replies; 5+ messages in thread
From: Carl @ 2002-09-13 9:37 UTC (permalink / raw)
To: urgrue, admin
At 12:16 13/09/2002 +0300, urgrue wrote:
>is there a way, in a bash script, to do something like:
>execute "this_command these_params"
>--if-its-not-done-in-600-seconds-then-kill-it-and-return-an-error-code
>
>situation is, i have a simple script that logs into remote boxes, and
>does some checks.
>it first pings each box to see if the route is up, if that fails it
>wont even try to log in.
>but sometimes, a box can be pinged but not logged into, for various
>reasons.
>in these cases, the ssh login attempt seems to just sit there and
>doesnt timeout, and the whole script hangs, waiting until ssh exits.
>which i have observed to take at times HOURS, at times it _never_ exits.
>
>any suggestions?
I can't give you a quick answer, but i use "expect" to do anything interactive
that i don't want to do manually. Stuff like setting passwords on multiple hosts
and checking disk space etc...
I read the blurb on expect and was sceptical on how important it can be
to a sys-admin but i'm now hooked and it is my first port of call for doing
routine things many times.
If you know tcl it will be a breeze and even if you don't it is fairly straight forward.
See http://expect.nist.gov for info on expect.
--
Carl
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: bash scripting..simple question
2002-09-13 9:16 bash scripting..simple question urgrue
2002-09-13 9:37 ` Carl
@ 2002-09-13 9:51 ` Michael Salmon
2002-09-13 14:55 ` Glynn Clements
2 siblings, 0 replies; 5+ messages in thread
From: Michael Salmon @ 2002-09-13 9:51 UTC (permalink / raw)
To: admin
On Friday, September 13, 2002 12:16:11 PM +0300 urgrue <urgrue@tumsan.fi>
wrote:
+------
| is there a way, in a bash script, to do something like:
| execute "this_command these_params"
| --if-its-not-done-in-600-seconds-then-kill-it-and-return-an-error-code
|
| situation is, i have a simple script that logs into remote boxes, and
| does some checks.
| it first pings each box to see if the route is up, if that fails it
| wont even try to log in.
| but sometimes, a box can be pinged but not logged into, for various
| reasons.
| in these cases, the ssh login attempt seems to just sit there and
| doesnt timeout, and the whole script hangs, waiting until ssh exits.
| which i have observed to take at times HOURS, at times it _never_ exits.
|
| any suggestions?
+-----X8
It is a little tricky, you need to start the first command in the
background and then sleep and kill that job if it is still running. Here is
an example from a Bourbe shell script:
rsh -n $gw test -x $cmd \&\& $cmd ${1+"$@"} > $tmp &
pid=$!
# timeout function
(
sleep 45
if kill -0 $pid > /dev/null 2>&1
then
kill -TERM $pid
fi
) &
wait $pid
/Michael
--
This space intentionally left non-blank.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: bash scripting..simple question
2002-09-13 9:16 bash scripting..simple question urgrue
2002-09-13 9:37 ` Carl
2002-09-13 9:51 ` Michael Salmon
@ 2002-09-13 14:55 ` Glynn Clements
2 siblings, 0 replies; 5+ messages in thread
From: Glynn Clements @ 2002-09-13 14:55 UTC (permalink / raw)
To: urgrue; +Cc: admin
urgrue wrote:
> is there a way, in a bash script, to do something like:
> execute "this_command these_params"
> --if-its-not-done-in-600-seconds-then-kill-it-and-return-an-error-code
The "netpipes" package includes the "timelimit" command, which does
exactly this:
TIMELIMIT(1) TIMELIMIT(1)
NAME
timelimit - spawn a subprocess and if the child does not
finish within the time limit either kill it, or exit,
leaving the child in the background.
SYNOPSIS
timelimit [ -v ] [ -nokill ] time command args
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: bash scripting..simple question
@ 2002-09-13 13:57 grottoBoy rant
0 siblings, 0 replies; 5+ messages in thread
From: grottoBoy rant @ 2002-09-13 13:57 UTC (permalink / raw)
To: urgrue, linux-admin
sleep will do what you want, i think.
I'm slow to give you the code, but the thought process is:
sleep 600 seconds
grep output from ps aux for the ssh login attempt maybe, if it hasn't exited
then kill the process and continue running the script, maybe?
your earlier code will have to make sure that ssh process exits properly on
successful completion...
----Original Message Follows----
is there a way, in a bash script, to do something like:
execute "this_command these_params"
--if-its-not-done-in-600-seconds-then-kill-it-and-return-an-error-code
situation is, i have a simple script that logs into remote boxes, and
does some checks.
it first pings each box to see if the route is up, if that fails it
wont even try to log in.
but sometimes, a box can be pinged but not logged into, for various
reasons.
in these cases, the ssh login attempt seems to just sit there and
doesnt timeout, and the whole script hangs, waiting until ssh exits.
which i have observed to take at times HOURS, at times it _never_ exits.
any suggestions?
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-09-13 14:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-13 9:16 bash scripting..simple question urgrue
2002-09-13 9:37 ` Carl
2002-09-13 9:51 ` Michael Salmon
2002-09-13 14:55 ` Glynn Clements
-- strict thread matches above, loose matches on Subject: below --
2002-09-13 13:57 grottoBoy rant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).