Operating System - HP-UX
1828621 Members
1270 Online
109983 Solutions
New Discussion

Cannot run command from CGI

 
SOLVED
Go to solution
Kalin Evtimov
Regular Advisor

Cannot run command from CGI

HI!
In a cgi-script I am trying to run

system ("/bin/top -d1 > /tmp/top.out");

this doesn't write anything to the file. Why?

Greetings!
Kalin
8 REPLIES 8
Warren_9
Honored Contributor

Re: Cannot run command from CGI

hi,

try "top -d 1 -f /tmp/top.out"

GOOD LUCK!!

Kalin Evtimov
Regular Advisor

Re: Cannot run command from CGI

It doesn't seem to ba e syntax problem, because from the command line they both work.
Peter Godron
Honored Contributor

Re: Cannot run command from CGI

Kalin,
To eliminate any problem with file creation:
system("echo test > /tmp/top.out");
if that works at least you have narrowed the problem to the top command.
Please Update
Kalin Evtimov
Regular Advisor

Re: Cannot run command from CGI

system("echo test > /tmp/top.out");

That worked!

What could be wrong with the top command, this is a bit difficult for me..:(
Steve Lewis
Honored Contributor
Solution

Re: Cannot run command from CGI

No. You must use -f if you want to send the output of top to a file, or else it will not be readable.

You have not writted how your CGI system command is executed. Is it from perl? from awk? from ruby? from python? from php?

the top command is definitely
"/bin/top -d 1 -f /tmp/top.out"

but if another user has already created that file, length zero, then your www user will not be able to overwrite it.

Check the output file permissions.

Kalin Evtimov
Regular Advisor

Re: Cannot run command from CGI

I am using the web-server from the Webmin-tool for UNIX Administration.
Thank you for the advice!
Peter Godron
Honored Contributor

Re: Cannot run command from CGI

Kalin,
so the re-direct works.
No try and capture any error messages:
system("/usr/bin/top -d1 > /tmp/top.out 2>&1");
Kalin Evtimov
Regular Advisor

Re: Cannot run command from CGI

Thank you for your idea Peter!
Steve's suggestion worked for me, I had to delete the top.out file once, so that it is could be created again from the webserver-user.

Greetings!
Kalin