LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-06-2008, 10:39 AM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL 6.x, 5.x, Fedora 20, Kubuntu 12.04, Solaris 10,8
Posts: 321

Rep: Reputation: 17
awk / nawk question - hostname


Hi,

I am trying to print a list of mount points from a remote host, and for some reason nawk is only printing the local HOSTNAME environment variable. I think this may be because ssh is stopping me.

Therefore I think I have to get nawk to print the output from the hostname command. How do I execute hostname, or do I feed the output into a variable and then print this within nawk ?

This is what I have been trying but failing with :

ssh 123.123.123.123 mount -v | grep 'type vxfs' | egrep -v '( /var/| /usr/openv)|.*abcbackup' | nawk -F" " '{print ENVIRON["HOSTNAME"]"," $3}'

Thanks
 
Old 03-06-2008, 11:18 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

You do know that only the mount -v part is executed on the other machine and the rest is executed locally? That also explains why you're getting the local HOSTNAME.

The whole pipe needs to be between single quotes. This will tell bash (local) not to touch the content and all is expanded/executed remotely.

I see you have single quotes in the pipe as well, you need to escape those.

Hoipe this helps.
 
Old 03-06-2008, 01:21 PM   #3
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL 6.x, 5.x, Fedora 20, Kubuntu 12.04, Solaris 10,8
Posts: 321

Original Poster
Rep: Reputation: 17
Hi drunna


Quote:
Originally Posted by druuna View Post
Hi,

You do know that only the mount -v part is executed on the other machine and the rest is executed locally? That also explains why you're getting the >local HOSTNAME.

ugh. thanks.


The whole pipe needs to be between single quotes. This will tell bash (local) not to touch the content and all is expanded/executed remotely.

I see you have single quotes in the pipe as well, you need to escape those.

hmm i did'nt realise that. really appreciate your help. thanks again.


Hoipe this helps.
So it now looks like :

ssh 123.123.123.123 'mount -v | grep \'type vxfs\' | egrep -v \'( /var/| /usr/openv)|.*abcbackup' | nawk -F" " '{print ENVIRON["HOSTNAME"]"," $3}\''

Thanks

Last edited by dazdaz; 03-06-2008 at 01:23 PM.
 
Old 03-07-2008, 01:35 PM   #4
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL 6.x, 5.x, Fedora 20, Kubuntu 12.04, Solaris 10,8
Posts: 321

Original Poster
Rep: Reputation: 17
I finally got it working with the following. Quite useful to keep a note of this for next time

$ ssh fs8888 "mount -v|grep \"type vxfs\"|egrep -v \"( /var| /usr/openv|/data/db_scratch|.*abcbackup)\"|nawk '{print ENVIRON[\"HOSTNAME\"] \",\" \$3}'"
 
Old 03-07-2008, 03:50 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Of course there's no need for grep or egrep in your command at all ;}
Code:
ssh fs8888 "mount -v |nawk '/type vxfs/ && ! /(\/var|\/usr\/openv|\/data\/db_scratch|.*abcbackup)/ {print ENVIRON["HOSTNAME"] \",\" \$3}'"


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nawk question - addition of a column dazdaz Programming 1 02-19-2008 11:47 AM
Nawk output omega71122 Solaris / OpenSolaris 3 08-16-2005 03:40 PM
nawk not available raees Linux - Software 3 05-02-2005 03:49 PM
Nawk issues michedlp Programming 1 02-25-2004 07:29 PM
awk question dilberim82 Programming 2 10-01-2003 07:12 PM


All times are GMT -5. The time now is 05:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration