Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

Given your comment, I suggest something like this:

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

share|improve this answer
No how i run the script is sh < ip.txt where ip.txt contains all the hosts address. – karthick87 Dec 13 '11 at 14:36
Okay, then you need to alter the script to work in parallel, or you spawn an instance of 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. – Martin Ueding Dec 13 '11 at 15:03

@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 &

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.