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?

Link to comment
Share on other sites

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)

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.