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

System calls in unix 1

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
hi all,

I am running a apache webserver on a solaris box. I am writing a cgi-script in perl. The problem is that i want my script to return the number of httpd processes the server is running. I am trying

$daemons = system("ps -ef | grep httpd | wc");
print $daemons;

However, this dosen't work. I get this error in the error logs
malformed header from script. Bad header = 40 357 3608 (which is the result of the call)

I have tried doing this will other system calls such as df -k but it dosent work. However, this works as a .pl program but not in a cgi script. Any ideas? Thanks for your time.

jim
 
I don't think you want to use 'system'. The 'system' call does not return the output of the called program. It returns an exit value( do perldoc -f system for details).

Instead of 'system', try backticks (the lower case char under ~).

$daemons = [red]`[/red]ps -ef | grep httpd | wc[red]`[/red];

HTH
If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
Also, if your script is a cgi script, then that script needs to print a legal html page, including all the required tags, such as

Content-type: text/html

<html>
<head>
</head>
<body>

... your printed lines go here ...

</body>
</html>

Hopefully I didn't miss anything - that's off the top of my head. The error you got was caused by printing output that didn't start with a standard html header(starting with the Content-type. Read up on cgi - find a good tutorial - maybe at
HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
I'd like to add that while being a convenient way using system calls via the backticks or in whichever way should be thouroghly testing before putting them on a production server. Especially when we are talking about CGI programs and you give users the possibility of entering valus that infulence how your script is run. BEWARE the evil metacharacters :)

Zodiak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top