ejaboneta Posted July 23, 2010 Share Posted July 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/208614-creating-files-in-linux-with-php-crontab/ Share on other sites More sharing options...
trq Posted July 23, 2010 Share Posted July 23, 2010 We have Apache installed on a centOS server. I'm not sure what this would have to do with Apache. We need to see the script, and your crontab entry. Have you checked cron's logs? Quote Link to comment https://forums.phpfreaks.com/topic/208614-creating-files-in-linux-with-php-crontab/#findComment-1089890 Share on other sites More sharing options...
ejaboneta Posted July 23, 2010 Author Share Posted July 23, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/208614-creating-files-in-linux-with-php-crontab/#findComment-1090243 Share on other sites More sharing options...
ejaboneta Posted July 23, 2010 Author Share Posted July 23, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/208614-creating-files-in-linux-with-php-crontab/#findComment-1090276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.