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


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-15-2013
Registered User
 
Join Date: Sep 2009
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Ssh with awk

hello,

I wish to launch a command ssh by getting back certain values in a file with awk.

Example of command ssh:

Code:
ssh -q lpar1 mount|grep /tmp/conf-1
ssh -q lpar2 mount|grep /tmp/conf-1


Example of file:

Code:
/tmp/conf-1 servers=lpar1 lpar2 lpar3 /tmp/conf-2 servers=lpar4 lpar5 lpar6

Sponsored Links
    #2  
Old 01-15-2013
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 7,165
Thanks: 229
Thanked 808 Times in 698 Posts
If there's a question in there, I'm not sure I understand it.
Sponsored Links
    #3  
Old 01-15-2013
Registered User
 
Join Date: Sep 2009
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
This is tne content of a file:

Code:
/tmp/conf-1 servers=lpar1 lpar2 lpar3
/tmp/conf-2 servers=lpar4 lpar5 lpar6

By leaving of the file, I would like to get back data with awk and launched an unix command in the awk like this:


Code:
ssh -q lpar1 mount|grep / tmp/conf-1 etc ...

Sorry , i don't speak english very well
    #4  
Old 01-15-2013
Registered User
 
Join Date: Jul 2012
Location: Chennai
Posts: 506
Thanks: 37
Thanked 64 Times in 62 Posts
In that case,


Code:
var="/tmp/conf-1 servers=lpar1 lpar2 lpar3"
 
echo $var | sed 's/=/ /g' | awk '{for(i=3;i<=NF;i++){print "ssh -q "$i" mount|grep "$1}}'

This should work
Sponsored Links
    #5  
Old 01-15-2013
Registered User
 
Join Date: Sep 2009
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks , it'good

But it is possible to execute the ssh command in the awk function ?
Sponsored Links
    #6  
Old 01-15-2013
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,577
Thanks: 501
Thanked 2,571 Times in 2,451 Posts
Sure it's possible, but awk is not shell, and ill-suited to it.


Code:
awk 'BEGIN { "ssh whatever" | getline }'

It'd be much better to run ssh outside of awk, and pipe it in.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SSH and AWK Scripting bradyd Shell Programming and Scripting 3 07-14-2011 06:17 PM
awk - skip x lines and ssh anthonyraj75 Shell Programming and Scripting 1 03-04-2010 10:16 AM
setting a variable, using SSH and awk? hcclnoodles Shell Programming and Scripting 5 10-28-2009 10:35 AM
Passing awk through ssh help gbarnes Shell Programming and Scripting 9 09-23-2009 04:34 AM
awk using ssh variable? RisingSun Shell Programming and Scripting 3 08-04-2008 12:07 PM



All times are GMT -4. The time now is 12:06 AM.