TECH SOLUTIONS

Click here to edit subtitle

Forums

Post Reply
Forum Home > Unix Learnings > Shell Script: ssh under while loop

Sourav Gulati
Site Owner
Posts: 83

When you try to do ssh in while loop  as follows:, it will do ssh once then quit the loop. In other words looping won't happen


while read line

do

 ssh  [email protected]$line "jps"

done


So the solution is run ssh as background process i.e use -n option with ssh as follows:


while read line

do

 ssh -n [email protected]$line "jps"

done


One more benefit, executing it in backgroud is that in case there is some error while doing ssh to some machine, loop wont quit since process is running in background. So it will fire ssh process on all other machines that appear after the erroneous machine in the file

 

 

 

--


February 4, 2013 at 7:39 AM Flag Quote & Reply

You must login to post.