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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi and system calls

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
hello,

I have a cgi script written in perl that uses a system call. it is system ("top -n 10 > top.txt");

However, this dosent work and i get the following message in my error logs

sh: Top command not found

Has anyone come across this before?

Thanks for your help

jim
 
Usually, for security reasons, the web server daemon is its own user in its own group. It has its own paths and abilities which are frequently less robust than most other users/groups.

Are you able to run other commands via 'system'? Something like 'cat' or 'ls'? If so, then it may be that your sys_admin has your web server setup so that it can not see some OS commands that could be dangerous. The 'top' command would be just such a command. It gives a lot of info about what is running on the machine.... not something you want to publish to the hacker community.


'just my thoughts
If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
thanks go boating

I can do other system calls such as ls etc.. i can also log in as webuser which is what the webserver runs as and do the top command. When you say webserver setup do you mean apache config which is what my web server is running or do you mean the configuration of the server hosting apache - which is the unix system?

thanks for your help
 
If the web server (Apache) is running as 'webuser' and you can log on as webuser and run top, then your CGI code should be able to also.

So, the problem appears tp be elswhere..... not sure where, though. How about we try a very simple piece of code to make sure nothing else is tripping us up here. Try copy/paste/save this into a file, dos2unix it, chmod +x, and hit it from a browser.

Code:
#!/usr/local/bin/perl
$it = (system("top -n 10  > top.txt"))/256;
print "Content-type: text/html\n\n";
print &quot;<HTML><HEAD><TITLE>Top system Test</TITLE></HEAD>
      <BODY><P>Ran top. Exit status: $it</P></BODY></HTML>&quot;;

That is about as simple as it gets. You should get an exit status of '1' back if the system call works.

See if that works. If it does, then we need to look at your original piece of code and see what may be corrupting the situation. If it does not, we'll look closer at the simple case.

On another issue.... do you mean to be catching the output of the 'top' command? If so, 'system' is not the way to do that trick. All 'system' will return is an exit status of the command that was called. You would need to use back ticks or a pipe to catch the output of 'top'.

HTH
If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top