Hi, this problem has had me stumped for weeks now.
I have written a compiled CGI script in C to rotate my log files each day. The problem is that I don't seem to be able to execute it from inside PHP. It runs fine if I access the file directly though.
The CGI doesn't have to return anything to the screen just execute it.
I am using a default installation of the MAMP server and I know the Apache server fairly well.

I have tried using:

and exec()

to execute my CGI from within PHP. If you have any ideas please let me know, it will be gratefully received.


Recommended Answers

All 4 Replies

Show the actual PHP code you are using to execute it.

Hi, I am currently using this to execute it.

function log_dump() {
	system('ls /cgi-bin/');
	$week = (date("Ymd") - 7);
	$bkfile = '../../logs/access.log';
	$table = 'page_log';
	$r  =  "SELECT * INTO OUTFILE '$bkfile' FROM `$table` WHERE `date_in` = $week";
	mysql_query( $r ) or die(mysql_error()); ;
	$t = "DELETE FROM `$table` WHERE `date_in` = $week";


Why not use system() command instead of exec() to execute the CGI program? IE:

system('/Applications/MAMP/cgi-bin/rotate.cgi ../logs/access.log');

Also, I notice the '?' after the command string, and no space before the '../logs/access.log' part. Possibly there is an error here? Finally, the bkfile variable is using '../../logs/access.log' instead of '../logs/access.log'. Was this intentional, or another typo?

Hi, I have tried the system command before with no luck.
After this I then changed my CGI to pick up the argument through the get_env(QUERY_STRING), which is a HTTP GET rather than a command line argument. For this reason I guess the '?' is needed but correct me if I'm wrong.

Also the bkfile variable is intentional as it is relative to the script that is calling the dump rather than the CGI.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.