Shell scripting- how do I do this?

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi

I want to write a script that SSH'es to a number of boxes
(i.e. for i in box1 box2 box3

do
..)

and so on, the script works perfectly unless one of the boxes is unavailable, in which case it grinds to a halt. Is there any way around this?

Thanks
 
Hi,

Have you tried executing each ssh as a background process?

Failing that, maybe a small Perl script that forks a new process for each ssh call would be an option?

Hope that helps.
Jim
 
hmm, I seem to remember a multi-ssh client that works by opening a seperate shell for each, and so they operate independantly, and executables can be each called seperately with the same variables etc. Can't remember what it was called, but google is your friend :S
 
If the server is down, something like this in your script should be ok to begin with ...

ping -c 2 $i 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
ssh ....
fi

Add an else statement if you want to be told that the remote host isn't responding. (eg; mail or snmp trap) You could also do something similar to check the return code from the ssh and set ConnectionAttempts in your ssh_config to something low.
 
Back
Top Bottom