Ssh with awk | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Ssh with awk

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-15-2013
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 28 August 2014, 3:29 AM EDT
Posts: 36
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
Last Activity: 20 October 2014, 2:03 AM EDT
Location: Zürich
Posts: 8,484
Thanks: 332
Thanked 1,047 Times in 914 Posts
If there's a question in there, I'm not sure I understand it.
Sponsored Links
    #3  
Old 01-15-2013
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 28 August 2014, 3:29 AM EDT
Posts: 36
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
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 10 July 2014, 12:57 PM EDT
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 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
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 28 August 2014, 3:29 AM EDT
Posts: 36
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
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 October 2014, 6:33 PM EDT
Location: Saskatchewan
Posts: 19,628
Thanks: 815
Thanked 3,334 Times in 3,123 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
Closed Thread

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 10:10 PM.