The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts 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 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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-13-2008
din din is offline
Registered User
 

Join Date: May 2008
Posts: 2
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
Reply With Quote
Forum Sponsor
  #2  
Old 05-14-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 734
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)
Reply With Quote
  #3  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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.
Reply With Quote
  #4  
Old 05-15-2008
din din is offline
Registered User
 

Join Date: May 2008
Posts: 2
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0