LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   awk / nawk question - hostname (https://www.linuxquestions.org/questions/programming-9/awk-nawk-question-hostname-626176/)

dazdaz 03-06-2008 10:39 AM

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

druuna 03-06-2008 11:18 AM

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.

dazdaz 03-06-2008 01:21 PM

Hi drunna


Quote:

Originally Posted by druuna (Post 3080169)
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

dazdaz 03-07-2008 01:35 PM

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}'"

Tinkster 03-07-2008 03:50 PM

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


All times are GMT -5. The time now is 08:45 AM.