Eytan Eytan - 1 year ago 86
Linux Question

ssh + ssh is stuck on remote machine in spite we set connection time out flag

I developed the following simple script in order to perform reboot on ~100 Linux machine

ssh $LINUX_MACHINE /var/tmp/restart.sh

after running this script couple of times ,

some times the ssh process is stuck! ( and loop is stuck on current machine )-

so how it can be - what could be the reason that in rare case ssh is stuck

and how to avoid that?

Answer Source

I'd suggest something rather different -- instead of having a fixed delay between instances, having a fixed maximum number of instances to run at a time. For instance, with that value at 25:

xargs -P "$numprocs" -J '{}' -n 1 -- \
  perl -e 'alarm shift; exec @ARGV' -- "$timeout" \
    ssh -nxaq -o ConnectTimeout=5 -o StrictHostKeyChecking=no '{}' /tmp/reboot.sh \
  <hostnames # if a file; use < <(awk ...) if a script providing per-line info

Note that -J {} is an extension which avoids bugs implicit in the specification for the (standards-mandated) -I {} xargs behavior. If it's not available, -I '{}' can be used instead -- but do read the man page to understand caveats.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download