Jump to content

Creating files in Linux with php crontab


ejaboneta

Recommended Posts

We have Apache installed on a centOS server. I wrote a script to create a file. When i run the script as root, the file is made, however when crontab runs the file, it can't open the file to write. I tried setting the the permissions to 755, and changing the owner to 'nobody' as I saw suggested somewhere but it's still not working. Does anyone know how I can get this to work?

There were no errors in crontabs log. I created my own log for the output. In that log, all I get is "Cant open file." from my script. When I run the script manually, it works.

 

PHP:

$callscript = "{my script here}";

$file = "calldirectory/makecall.call";
$filehandle = fopen($file,'w') or die('Cant open file.');
fwrite($filehandle,$callscript) or die('Cant write to file');
fclose($filehandle);

 

Crontab entry:

* * * * *  php /var/www/html/checkmail/index.php >> /var/www/html/checkmail/log

 

Crontab log:

Jul 22 21:13:01 vici crond[15436]: (root) CMD (php /var/www/html/checkmail/index.php >> /var/www/html/checkmail/log.php)

 

 

I finally found what I was doing wrong! I was using a relative path to the directory where I wanted the file instead of an absolute... I changed this:

$file = "calldirectory/makecall.call";

to this:

$file = "/var/www/html/calldirectory/makecall.call";

 

 

Thanks, even though I figured it out before anyone could reply!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.