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!

Exec a script in awk 1

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

How can I exec a script using awk(system). Firsly I create a file with the nessary info, chmod 755 and then exec the script.

awk -F " " '{
split($1,a,".")
STAC=a[1]
datatype=a[2]
DSN=a[3]
TSN=a[4]
D_T=$5" "$6
cmd="Timestamp " D_T "
cmd | getline TIME; close(cmd);
printf "Jack %s %s \n",TSN,STAC > $1
system("/usr/bin/chmod 777 " $1)
{ if (system("$1 ") != 0) {
printf("Failed\n");
} else {
printf("Done\n")}}
}' Filename_txt

Many Thanks
Chris
 
Have you tried to replace this:
if (system("$1 ") != 0)
By this ?
if (system($1) != 0)
But the filename referred by $1 must be in a directory in the PATH environment variable.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Thanks once again,

Yes I have tried it, and the error mesg was "sh: filename not found
Failed!!!". The awk script is in the same dir where the filename is being created. What next?

Thanks
Chris
 
Have you tried this ?
if (system("./"$1) != 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Yes, and the result was "sh: ./: cannot execute
Failed!!!".

Thanks
Chris
 
And $1 has no leading space ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Oops, I did not see ("./"$1), instead I saw ("./$1").
My mistake. Anyway it does work.

Many Thanks Once Again
Chris

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top