1833588 Members
4198 Online
110061 Solutions
New Discussion

Hang script

 
SOLVED
Go to solution
Sachin Patel
Honored Contributor

Hang script

I have simple script that goes and remsh to system but if system is in certain stat it will hang. how do I stop that

Example:
set systems= (client1 client2 client3)
foreach system ($systems)
remsh $system echo $shell
end

It hangs on client2. I can ping client2. I can't login because home is nfs mount. When I try telnet client2 it says trying ip...

How do I stop this hanging and goes to client3?

Sachin
Is photography a hobby or another way to spend $
10 REPLIES 10
Volker Borowski
Honored Contributor

Re: Hang script

Hello,

if it is not sure, that your remsh command returns properly, you'll need to start it in background with "&"
and record PID of background process (man csh).

After this "sleep secs_long_enough"

After this check if PID still active and if yes, kill it and take a status-note.

Porceed to next loop then.

I am no csh-fan, so I have limits to give you a sample, but this should lead the way.

Volker
Tom Danzig
Honored Contributor

Re: Hang script

You might want to try rexec instead of remsh. It doesn't source profiles/environments and may work for you.
Tom Danzig
Honored Contributor

Re: Hang script

Just remembered that rexec requires a password. Ignore my previous suggestion.
someone_4
Honored Contributor

Re: Hang script

Hello I do remsh scripts but they dont hang even if the host is down. But here is how I do my list of many hosts.hostnames is a file in /home/richard/cron that has a list of the hosts in one column. Do you get any erros from your script?


#!/usr/bin/sh
cd /home/richard/cron
HOSTNAME_FILE=hostnames
for host in $(cat $HOSTNAME_FILE)
do
echo $host
remsh $host -l root hostname
done
#### end of script
exit 0
Klaus Crusius
Trusted Contributor

Re: Hang script

The attached C-Program will start a process and kill it after 5 seconds.

compile: cc -Aa killafter.c -o killuser

usage in your application:
killafter remsh echo $shell

Klaus
There is a live before death!
Klaus Crusius
Trusted Contributor

Re: Hang script


Improved version.
There is a live before death!
linuxfan
Honored Contributor
Solution

Re: Hang script

Hi Sachin,

You could try something like this
=========Cut here==============
#!/bin/ksh

export systems = "client1 client2 client3"

for i in $systems
do
echo $i
(remsh $i -n "echo $SHELL") &
MYPID=$!
# echo $MYPID

sleep 5
ps -ef |grep -v grep |grep $MYPID >/dev/null 2>&1

if [ $? = 0 ]
then
echo "Connection to client $i is hung"
kill $MYPID
fi
done
=========Cut here==============

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Sachin Patel
Honored Contributor

Re: Hang script

Thanks all of you.

I have a script that runs command1 and that commnad1 remsh for multiple systems.

I will grep for command1's pid and then I will search for child pid of that pid and kill it if it hangs more then 5 seconds.

R.U your solution is very much what I was looking for.

Sachin
Is photography a hobby or another way to spend $
Bill Hassell
Honored Contributor

Re: Hang script

The original problem (hang on each remsh) is a classic due to the interactive nature of remsh. The key is remsh -n which allows an async connection to the remote side.

Attached is a script to ping a list of hosts from a file formatted like /etc/hosts, and specify how long to wait before giving up and killing the process. It uses the shell's ability to return a background PID.


Bill Hassell, sysadmin
Mladen Despic
Honored Contributor

Re: Hang script

Bill, thanks for the script. It works well, although I had to modify it for my system. It looks like the ping command on my system does not accept -m option. Is it only available with most recent versions of ping? I have:

# what /usr/sbin/ping
/usr/sbin/ping:
PHNE_16158 ping.c $Revision: 1.8.119.5 $ $Date: 98/07/23 14:27:01 $
NET: Version: B.11.00 $Date: 97/10/15 10:44:23 $