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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
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
  #2 (permalink)  
Old 05-14-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
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 (permalink)  
Old 05-15-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #4 (permalink)  
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
  #5 (permalink)  
Old 03-05-2009
sags sags is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 1
Please check if this helps:

for i in `cat serverlist`; do ssh $i "for i in \`lspv | awk '{print \$1}'\`; do echo \$i; done"; done
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0