Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 2 down vote accepted

Given your comment, I suggest something like this:

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

wait
share|improve this answer
    
No how i run the script is sh scriptname.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 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. –  queueoverflow Dec 13 '11 at 15:03
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.