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 |
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. |
Hi drunna
Quote:
ssh 123.123.123.123 'mount -v | grep \'type vxfs\' | egrep -v \'( /var/| /usr/openv)|.*abcbackup' | nawk -F" " '{print ENVIRON["HOSTNAME"]"," $3}\'' Thanks |
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}'" |
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. |