![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| while loop inside while loop | panknil | Shell Programming and Scripting | 0 | 01-07-2008 12:49 PM |
| For loop | xramm | HP-UX | 3 | 10-10-2007 03:20 PM |
| While Loop | hemangjani | Shell Programming and Scripting | 2 | 11-02-2006 11:01 AM |
| for loop | munnabhai1 | Shell Programming and Scripting | 3 | 04-06-2006 03:30 PM |
| how to get the similar function in while loop or for loop | trynew | Shell Programming and Scripting | 3 | 06-17-2002 12:09 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
Whatever you really want, chmod 777 is almost guaranteed to be wrong; I changed it to 644. 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. |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|