ssh command in a loop ?
I am trying to run the same command(s) on the many destination servers from my source server.
source server user "report" ssh keys are added to all destination hosts.
cat hosts.cfg | while read line
ssh root@$line uname -a
Linux gadikota_dev01 2.6.9-67.EL.bz450900.HFsmp #1 SMP Thu Jun 19 16:25:45 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
as you see above even when i am running a loop its just splitting the output of first server and not others.
Anything special i need to do ? or is there a different way ?
Yes. Add option -n to the ssh command. The standard input coming from the pipe becomes the standard input of the remote command (this is the way ssh works) and when the ssh command terminates it sends a SIGTTIN signal to the local shell: it closes the standard input and causes the loop to exit. The -n option redirects the standard input from /dev/null, leaving the stdin of the local shell untouched. Hope this helps.
Another alternative would be to use a for loop:
P.S.: I *really* hope you don't have root-logins via ssh enabled,
possibly even w/o passwords?
Both solutions work great. Thanks Guys for your help.
|All times are GMT -5. The time now is 06:25 AM.|