PHP System commands

By dr.engnr ·
I'm trying to execute the following system commands throught php:

system("tracert -d | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> trace.txt");

i'm getting an 'invalid syntax' error. It seems to have to do with the quotes, but they're necessary for the command. Any help is appreciated.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -


by dr.engnr In reply to PHP System commands

this is a windows machine with unxutils installed. most unix commands are available.

Collapse -

Question about gawk

by NetMan1958 In reply to PHP System commands

I didn't know you could post to a web url from within gawk. Are you sure that is possible? I thought you would have to use curl for that.

Collapse -


by dr.engnr In reply to Question about gawk

it's actually just pulling the individual data i need from the tracert and surrounding the $8 column with url text.

Collapse -


by NetMan1958 In reply to PHP System commands

Try replacing the double-quotes before tracert and after trace.txt with single quotes. For instance:

system('tracert -d | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> trace.txt');

I can't test that right now so let me know the results.

edited to add:
see this article

Collapse -


by dr.engnr In reply to Quotes

This seems to be "better". instead of immediately failing it is processing but no file is exported. I have tried assigning the command to a variable $command and printing it. It can be pasted directly into a prompt and runs fine.

is there a reason anyone can see that >> wouldn't work as written?

Collapse -

Try This

by NetMan1958 In reply to yeah

system('tracert -d | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"\"$8\"^&submit=ReverseIP\" \",\" \"Window2\" >> trace.txt}"');

Collapse -


by dr.engnr In reply to Try This

damn. i've tried about every combination of ' and " i can conceive.

Collapse -


by dr.engnr In reply to Try This

the text file actually gets created using the following code, but it stays empty even though the script appears to be running.
system('tracert -d | grep "ms" | gawk "{print ($2+$4+$6)/3 \",\" \"\"$8\"^&submit=ReverseIP\" \",\" \"Window2\"}" >> H:\WHO-IS.NET\trace.txt ');

any idea what i have to do?

Collapse -

Output Redirection

by NetMan1958 In reply to strange

Since gawk is what is actually creating the output that you want in the file, you need to move your output re-direction(>> H:\WHO-IS.NET\trace.txt) inside the curly braces.

I don't have PHP running on a windows machine so I can't experiment with it here.

Collapse -


by dr.engnr In reply to strange

what a p.i.t.a. just figured out what it was. because i am using unxutils i had to copy the grep.exe and gawk.exe into the c:\windows directory as well as system32. even though the commands function correctly when pasted to a prompt i guess the system() command needs all files in both locations...


Related Discussions

Related Forums