Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a script and argument within awk

Status
Not open for further replies.

ranjit

Technical User
Apr 14, 2000
131
GB
[tt]
Is it possible to run a script within awk presenting a parsed argument to it?
My work around at present is to print the syntax and any arguments to a file and execute the file outside of the awk statement.
Can the following line be run inside an awk statement:
/opt/itmcmd server -h /opt/ITM start ARG


###Script extract

/opt/IBM/ITM/bin/cinfo -r|nawk -v ARG=$VAL 'BEGIN {
RUNSCRIPT="/tmp/runscript"
FLAG=1 }

$0 ~/running$/{ FLAG=0 }

END { if(FLAG==1) {
printf("%s%s%s\n", "/opt/itmcmd server -h /opt/ITM start"," ",ARG) >RUNSCRIPT }
}'


# Work around solution
/tmp/runscript >/dev/null 2>&1
[/tt]
 
Hi

To run an external command form [tt]awk[/tt] use the [tt]system()[/tt] function.

Or if you have [tt]gawk[/tt], you can run a command by piping its input and/or output from/to the [tt]awk[/tt] script.

At least, if I understand correctly what you want.

Feherke.
 
Thanks for the reply. I'm aware of the system command, as in
system("/tmp/myscript")

However the system command doesn't appear to accept the argument presented to the script (via the -v option) I wish to run.

script syntax...

myscript [arg1]
 
A starting point:
system("/opt/itmcmd server -h /opt/ITM start " ARG)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Many thanks PHV - it's now resolved.

My mistake when using system was to also enclose the ARG in quotes.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top