0

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:

passthru()
system()
and exec()

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

Thanks,
Daryll.

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by daryll1
0

Hi, I am currently using this to execute it.

function log_dump() {
	exec('/Applications/MAMP/cgi-bin/rotate.cgi?../logs/access.log');
	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";
	mysql_query($t);
	
	
}

Cheers.

0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.