- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- executing a shell command within a awk command.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 06:15 PM
05-16-2006 06:15 PM
I am trying to execute a shell command from the awk script. But, It is not getting executed.
This is what I am trying =======>
sliam15:/ # cfsmntadm display sliam15 | awk '/mnt/ { print $1 }'
/mnt/sdg1/vol1
/mnt/sdg1/vol2
/mnt/sdg1/vol3
/mnt/sdg1/vol4
/mnt/sdg1/vol5
/mnt/sdg1/vset1
sliam15:/ # cfsmntadm display sliam15 | awk '/mnt/ { cfsmount $1 }'
Actually, it is not executing command "cfsmount" at all.
************************************************
I can execute the command mannually
sliam15:/ # cfsmount /mnt/sdg1/vol1
Mounting...
[/dev/vx/dsk/sdg1/vol1] mounted successfully at /mnt/sdg1/vol1 on sliam15
[/dev/vx/dsk/sdg1/vol1] mounted successfully at /mnt/sdg1/vol1 on sliam16
*****************************************************
How could I execute it in similar manner?
I know, I can use for loop and then cfsmount one by one. But, I want to know why the command I have given is not working?
Thanks in advance.
Thanks & regards,
Prasad.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 06:23 PM
05-16-2006 06:23 PM
Re: executing a shell command within a awk command.
how about using xargs?
# cfsmntadm display sliam15 | awk '/mnt/ { print $1 }' | xargs -n 1 cfsmount
GOOD LUCK!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 06:44 PM
05-16-2006 06:44 PM
Re: executing a shell command within a awk command.
That was gr8.
I have one query related to xargs
I wanted to specify some options to the command given with xargs.
I tried this
sliam15:/ # cfsmntadm display sliam15 | awk '/mnt/ { print $1 }' | xargs -n1 echo $1 Test
Test /mnt/sdg1/vol1
Test /mnt/sdg1/vol2
Test /mnt/sdg1/vol3
Test /mnt/sdg1/vol4
Test /mnt/sdg1/vol5
Test /mnt/sdg1/vset1
Not getting why string "Test" is printed first and then the actuall mount point. It should have been printed the other way.
Thanks Again.
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 06:54 PM
05-16-2006 06:54 PM
Re: executing a shell command within a awk command.
i guess since $1 for the echo is "" (null string).
then the echo command will look like
"echo Test [the value pass from awk]"
GOOD LUCK!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 07:40 PM
05-16-2006 07:40 PM
SolutionThus the actual execution of your echo will be like
echo $1 TEST /mnt/sdg1/vol1
echo $1 TEST /mnt/sdg1/vol2
and in this case $1 is null as it has not been set anywhere, hence the output.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2006 09:11 PM
05-16-2006 09:11 PM
Re: executing a shell command within a awk command.
I found two ways to solve the problem
1. Use xargs.
cfsmntadm display sliam15 | awk '/mnt/ { print $1 }' | xargs -n 1 cfsmount
2. Use system()
cfsmntadm display slpam15 | awk '/mnt/ { system ( "cfsumount " $1 ) }'
Thanks & regards,
Prasad