I've created a C script that rotates logs on my web server. It needs to receive 2 arguments, one whether the rotated log will be zipped and the other is the location of the log file.
This works fine in command line but I cannot get it to execute with the arguments in PHP.
Any help would be greatly appreciated.
My C script is below, usually compiled into rotate.cgi.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main( int argc, char *argv[] )
{
char file[100];
char file1[100];
strcpy(file, argv[2]);
strcpy(file1, argv[2]);
char buffer[50];
char comm[50];
char test[2];int i = 0,counter1 = 0;
struct tm *d;char li[13];
time_t now;
time(&now);
d = localtime(&now);
strftime(li, 25, "%F:%T", d);
sprintf (buffer, "%s.%s", file, li);
rename(file, buffer);
FILE *fp;
fp=fopen(file, "w");
fclose(fp);
if(strcmp(argv[1],"yes")==0)
{
sprintf(comm, "gzip %s.%s",file1,li);
system(comm);
}
if(strcmp(argv[1],"all")==0)
{
sprintf(comm, "gzip %s.*",file1);
system(comm);
}
exit(0);
}