Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Ssh with awk

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-15-2013
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 7 January 2015, 6:20 AM EST
Posts: 39
Thanks: 1
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 Unix and Linux 01-15-2013
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 27 August 2015, 3:25 PM EDT
Location: Zürich
Posts: 8,575
Thanks: 337
Thanked 1,080 Times in 938 Posts
If there's a question in there, I'm not sure I understand it.
Sponsored Links
    #3  
Old Unix and Linux 01-15-2013
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 7 January 2015, 6:20 AM EST
Posts: 39
Thanks: 1
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 Linux
    #4  
Old Unix and Linux 01-15-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 14 August 2015, 12:11 PM EDT
Location: Chennai
Posts: 573
Thanks: 50
Thanked 75 Times in 73 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 Linux
Sponsored Links
    #5  
Old Unix and Linux 01-15-2013
khalidou13 khalidou13 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 7 January 2015, 6:20 AM EST
Posts: 39
Thanks: 1
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 Unix and Linux 01-15-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 27 August 2015, 3:37 PM EDT
Location: Saskatchewan
Posts: 20,901
Thanks: 916
Thanked 3,732 Times in 3,486 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:28 AM.