From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Salmon Subject: Re: bash scripting..simple question Date: Fri, 13 Sep 2002 11:51:27 +0200 Sender: linux-admin-owner@vger.kernel.org Message-ID: <160000.1031910687@ws4065> References: <20020913091611.GA29785@fede2.tumsan.fi> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20020913091611.GA29785@fede2.tumsan.fi> Content-Disposition: inline List-Id: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: admin On Friday, September 13, 2002 12:16:11 PM +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? +-----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.