1

I have setup-ed keybased authentication to access all my client machines using ssh. However if i run anyscript in these clients, and suppose if particular hosts is down the terminal hangs in that session and it takes long time to go to the next hosts. Is there any other way to solve this issue? Or is it possible to skip the host which is down so that it should go with the next host? I am using ubuntu 11.04. Can some one help me? Thanks in advance.

2 Answers 2

2

Given your comment, I suggest something like this:

while read -r line
do
    echo "$line" > sh scriptname.sh &
done < "$file"

wait
2
  • No how i run the script is sh scriptname.sh < ip.txt where ip.txt contains all the hosts address.
    – karthick87
    Dec 13, 2011 at 14:36
  • Okay, then you need to alter the script to work in parallel, or you spawn an instance of scriptname.sh for each line in the ip.txt file. You would need a wrapper script which reads from the file and then spawns the instances with & and uses wait to finish will all the workers. Dec 13, 2011 at 15:03
0

@queueoverflow's answer is correct, but I thought it was unnecessarily complicated. Maybe this is easier to read?

ssh server1 do something &
ssh server2 do something at the same time &
ssh server3 do yet more things &
wait

The & means launch it in the background, and wait means hang until all the background tasks have exited. All the tasks will run in parallel, and the whole process should take the time of the longest task, and no more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .