Execute command from awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute command from awk
# 1  
Old 05-15-2012
Execute command from awk

This seemed straight forward until I tried to code it.

I'm running ioscan -fuNC disk to get list of disk including hardware path. What I'm trying to do is use awk to take this output, extract hardware path, and pass that as a variable to
Code:
ioscan -P wwid -N -H 64000/0xfa00/0x1a | grep ^disk

and then add the wwid to the rest of the original commands output. Below is basically psuedo code of what I'm trying to get at.

Code:
ioscan -P wwid -N -C disk | awk 'var1=(ioscan -P wwid -N -H $3 | grep ^disk | awk '{print $4}') {print $1 $2 $3 $4 $var1}'

Question is how do I run the ioscan from within awk and pass in the field variable as input and assign the return to a variable?

or

If someone knows how to run ioscan to get all this in one shot that would be great also.

Thanks.

Last edited by Scrutinizer; 05-15-2012 at 02:18 PM..
# 2  
Old 05-15-2012
Please do not leave people guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions being used, or this thread will be closed.
# 3  
Old 05-15-2012
You can do that 'outside' of awk, incidentally, with awk -v VAR="`command`".

But if you show the input you have and output you want we can help you find better ways.
# 4  
Old 05-15-2012
Sorry,
OS is hpux 11.31.

Expected input.

Code:
root:common dc40rx:/home/oracle # ioscan -fuNC disk
Class     I  H/W Path  Driver S/W State   H/W Type     Description
===================================================================
disk      3  64000/0xfa00/0x0   esdisk   CLAIMED     DEVICE       HP      DG072A9BB7
disk      4  64000/0xfa00/0x1   esdisk   CLAIMED     DEVICE       HP      DG072A8B54
disk      5  64000/0xfa00/0x2   esdisk   CLAIMED     DEVICE       HP      DG072A8B54
disk      7  64000/0xfa00/0x3   esdisk   CLAIMED     DEVICE       TEAC    DVD-ROM DW-224EV
disk     19  64000/0xfa00/0x9   esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     20  64000/0xfa00/0xa   esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     21  64000/0xfa00/0xb   esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     22  64000/0xfa00/0xc   esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     25  64000/0xfa00/0xd   esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     34  64000/0xfa00/0x10  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5
disk     35  64000/0xfa00/0x11  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5
disk     41  64000/0xfa00/0x12  esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     42  64000/0xfa00/0x13  esdisk   CLAIMED     DEVICE       EMC     SYMMETRIX
disk     47  64000/0xfa00/0x19  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5
disk     48  64000/0xfa00/0x1a  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5
disk     49  64000/0xfa00/0x1b  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5
disk     50  64000/0xfa00/0x1c  esdisk   CLAIMED     DEVICE       DGC     CX500WDR5


Expected output is same with wwid as the 9th column.

Last edited by Corona688; 05-15-2012 at 12:26 PM..
# 5  
Old 05-15-2012
Hmm.
Code:
awk -v lastcol="LASTCOL" 'NR>2 { $(NF+1)=lastcol } 1'

You can put whatever you want for LASTCOL, including things in backticks, since it's not inside the awk code itself, it's just another string in a commandline.
# 6  
Old 05-15-2012
I'm following what you're doing but I think I still need the field data from the first command to act as input to the second while still retaining the other field values for printing the output. I think I'm just going to append both outputs to a file, load in database, and reaggregate using SQL. thanks.
# 7  
Old 05-15-2012
You mean, the value of lastcol needs to change while it's running?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. Shell Programming and Scripting

Need help to execute command

HI, I have a directory called input directory called "input", The "input" directory contains file names (file1,file2,file3,file4), I want to write a command so that it will display all the file names with comma separated. Desired output: file1,file2,file3 so on.... Regards Akshay... (2 Replies)
Discussion started by: akshu.agni
2 Replies

5. Shell Programming and Scripting

awk and execute

Hi All, I need this to execute and not just print on Red Hat ent 4 bash shell. cat /etc/passwd|grep db2 | awk -F":" '{print "cat /etc/group | grep ",$4}' Output: cat /etc/group | grep 1000 (I don't want this to print but execute) Thanks for any comment you may add. (2 Replies)
Discussion started by: itik
2 Replies

6. UNIX for Dummies Questions & Answers

how to execute an command this way

How to make it works this way? echo dir1\/*.txt ; echo dir1\/*.html | xargs wc -l dir1/*.txt wc: dir1/*.html: No such file or directory what i'm trying to do it to "wc dir1/*.txt" and "wc dir1/*.html" (2 Replies)
Discussion started by: Bornay6ah
2 Replies

7. Shell Programming and Scripting

How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example: mycmd='' if ...; then $mycmd='sudo ' fi $mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile res=`$mycmd` (I'm also not sure of the best way to execute the command from the... (1 Reply)
Discussion started by: littlejon
1 Replies

8. Shell Programming and Scripting

awk and execute command ???

If I have a flat file date.txt separate by a tab date1 date2 count 20060226 20060225 2 20060227 20060226 2 20060228 20060227 5 20060314 20060228 2 20060315 20060314 1 If $3 (count) is 5 then execute the script testit.ksh with... (13 Replies)
Discussion started by: sabercats
13 Replies

9. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies

10. UNIX for Dummies Questions & Answers

How does this command execute?

Can somebody give me the explanation for this command line: ps>newfile<infile wc -l ? I am totally confused with the order of its execution.. :confused: Thanx, Saneesh Joseph. (3 Replies)
Discussion started by: saneeshjose
3 Replies
Login or Register to Ask a Question