Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ssh run in "for" loop redirection to separate files - how to?

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
just an example:

This works fine:
ssh ahost1 uptime >ahost1_uptime

This doesn't work at all:
for i in ahost1 ahost2;do ssh $i 'uptime' >$i_uptime;done

(instead of writting the outputs to files I got the 'uptimes' on stdout)

I need to save the output in separate file on local machine (where the "for" loop is being run).

thx for any tip,!

 
it's looking for a variable named i_uptime...

try it like this:
for i in ahost1 ahost2;do ssh $i 'uptime' >$[red]{[/red]i[red]}[/red]_uptime;done


HTH,

p5wizard
 
p5wizard's comment is the most likely problem - it's a good idea to *always* explicitly mark your variable names.

Also, I'd add to use the "-n" flag to "ssh" if you're using OpenSSH. I generally don't use for loops, but I use a lot of "while read" loops, and the -n prevents ssh from stealing the local stdin and breaking the loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top