![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| while loop inside while loop | panknil | Shell Programming and Scripting | 0 | 01-07-2008 09:49 AM |
| For loop | xramm | HP-UX | 3 | 10-10-2007 11:20 AM |
| While Loop | hemangjani | Shell Programming and Scripting | 2 | 11-02-2006 08:01 AM |
| for loop | munnabhai1 | Shell Programming and Scripting | 3 | 04-06-2006 11:30 AM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 08:09 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using ssh with a for loop
How do you do an ssh on a for statement. I have done ssh on individula lines of code before with no problems.
#!/usr/bin/ksh cat server_list.txt | while read line do ssh $line "for i in `lslpp -l |grep tsm` do lslpp -Lc $i |grep -v State |tr ':' ',' |awk -F, '{print $2, "," , $3}' done" > ./test.csv done; chmod 777 test.csv this is what I get the data is blowing up ? ksh: syntax error at line 3 : `tivoli.tsm.client.ba.32bit.base' unexpected |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
For starters, the multiple quotes in the string will be confusing it, change the choice of quotes in the awk.
Also, you don't need ksh for that, use a lighter shell (like /bin/sh) |
|
#3
|
|||
|
|||
|
You can avoid some of the quoting issues by using a here document. In my limited testing, this causes the remote hosts' MOTD messages to be displayed, which may or may not be a problem for you; depends on the SSH version and stuff like that, too, I guess.
Code:
#!/bin/sh
while read host
do
ssh $host <<"__HERE"
for i in `lslpp -l |grep tsm`
do
lslpp -Lc $i |grep -v State |tr ':' ',' |awk -F, '{print $2, "," , $3}'
done
__HERE
done <server_list.txt > ./test.csv
chmod 644 test.csv
Looks to me like the redirection to test.csv was also in the wrong place (you would be overwriting it for each host) so I changed that as well. |
|
#4
|
|||
|
|||
|
Hi all, Thank you for all the advise.
Unfortunately there are some interesting interactions going on either from the shell or the ssh in relation to the while. ERA I tried your suggestion and I got this. Tried the -t & -T but no go " Pseudo-terminal will not be allocated because stdin is not a terminal. Pseudo-terminal will not be allocated because stdin is not a terminal. Pseudo-terminal will not be allocated because stdin is not a terminal. Pseudo-terminal will not be allocated because stdin is not a terminal. " smiling dragon I did try different varrations of the quoting but still something with while and the ssh. Went with this for now but I will continue trying to get while to work. Thanks for the feedback. #!/usr/bin/ksh for line in `cat server_list.txt` do echo $line echo "***********" ssh $line lslpp -Lc |grep tsm |awk -F : '{print $2, "\t", $3}' echo done |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|