rsh timeout technique needed

310 views
Skip to first unread message

Ted Estes

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
All,

Problem:
I need help finding a way to stop the attempt of a remote command after
a given time. Sometimes an rsh command gets stuck on a system that isn't
quite well and doesn't return. The sick system responds to ping but is
just anti-social.

Background:
I currently have to regularly execute remote commands on around 300 Sun
workstations. I naturally do this from a trusted host that has been
added to all the workstations .rhosts file. Then I have a script read
the hosts from a plain text file with the workstations hostnames in it.

I typically use something like:

#!/bin/sh
# load variable with hostnames
hosts=`cat /tmp/workstations`
# do the following on each host
for ws in $hosts
do
# only try the remote command if the system is up
if ping $ws 2
then
# this is where it gets stuck on sick systems
rsh $ws 'command'
else
echo $ws not responding
fi
done

Workaround:
Right now I'm trapping signal 3 (QUIT) to skip that host if it doesn't
respond after a while. But I would like a solution that doesn't require
interaction.

Thanks in advance....
Ted

--
______________________________________________________________
Ted Estes Phone: 425-487-8073
UNIX System Administrator Fax: 425-487-8177
ATL Ultrasound Email: tes...@atl.com

Donn Cave

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
Ted Estes <tes...@atl.com> writes:
| Problem:
| I need help finding a way to stop the attempt of a remote command after
| a given time. Sometimes an rsh command gets stuck on a system that isn't
| quite well and doesn't return. The sick system responds to ping but is
| just anti-social.

Might try something like this.

Donn Cave, University Computing Services, University of Washington
do...@u.washington.edu
-----------------------------
#!/bin/sh

timeout=$1
case $timeout in
[1-9]*) shift;;
*) timeout=10;;
esac

case $# in
0) echo 'Usage: timeoutrsh [timeout] cmd' >&2; exit;;
esac

rsh "$@" &
p=$!
(sleep $timeout; kill -1 $p) &
k=$!

wait $p
exit=$?
# Normal exits are 0..127, signals are 128+signo
case $exit in
129)
echo '(timed out)' >&2
;;
*)
# Kill the killer.
kill $k
;;
esac
exit $exit

Jacob Langford

unread,
May 2, 1999, 3:00:00 AM5/2/99
to
Ted Estes wrote:

> All,


>
> Problem:
> I need help finding a way to stop the attempt of a remote command after
> a given time. Sometimes an rsh command gets stuck on a system that isn't
> quite well and doesn't return. The sick system responds to ping but is
> just anti-social.
>

I write most of my scripts in perl, which has an alarm() function. It is
good for just this purpose.


#!/usr/local/bin/perl -w

$seconds = 3;
chop($date = `date`);

select(STDOUT); $| = 1;

local $SIG{ALRM} =
sub {
die "Stopping ping.";
};

for ($i=1; $i<256; $i++) {

$host = "128.174.135.$i";
eval {
open (PING, "ping $host |");
alarm $seconds;
$responses = 0;
while (<PING>) {
++$responses;
}
};

close (PING);
if ($responses > 1) {
print "$host, $date, ALIVE\n";
} else {
print "$host, $date, DEAD\n";
}

}


for example:

Jacob


Reply all
Reply to author
Forward
0 new messages