1

I have a PHP script which i can run from mi CLI just fine, I need this script to run every 5 min so it will automatically fetch new data for me. To run my script from a terminal i call php retsphp.php --mode=new

Based on all what i found online i used crontab -e

*/5 * * * * /usr/bin/php -f /var/www/html/PHRETS/retsphp.php --mode=new > /var/log/retscron.log

I dont see ny retscron.log created and the only thing i see is in the syslog

Feb 13 08:25:01 rets-php CRON[7279]: (user1) CMD (/usr/bin/php -f /var/www/html/PHRETS/retsphp.php --mode=new > /var/log/retscron.log) Feb 13 08:25:01 rets-php CRON[7278]: (CRON) info (No MTA installed, discarding output)

i cant find any error why it fails

3
  • 1
    Does the php process have permission to write a file in in /var/log? Is the process running as www-data user? Also, do you wish to overwrite the file each time? I notice you are using ' > ' which will overwrite the file. Using ' >> ' instead would append to the file, not overwrite it. Maybe create the file first then change file ownership.
    – da_kingpin
    Feb 13, 2020 at 16:56
  • Thanks, i am getting closer to the problem. As the user did not have permission to write the file it failed but did not create any kind of error other then the message to MTA. So i installed postfix and was able to find the permission issue. Also after fixing that it didnt like the -f so i removed that
    – NoSoup4you
    Feb 13, 2020 at 16:58
  • The "No MTA installed, discarding output" means that the command has failed, but that it had nowhere to output its error messages. The cron system then tries to mail you the error messages, but there is no mail server on the system (MTA = Mail Transfer Agent) so cron gives up and just logs a message to the syslog.
    – Jos
    Feb 13, 2020 at 17:37

1 Answer 1

0

After some digging i was able to solve my Issue..

a) i ended up installing Postfix to be able to get debug info from the failing cronjob which showed me the following error

/bin/sh: 1: cannot create /var/log/retscron.log: Permission denied

b) after fixing that it did not like the -f so i removed that

c) the final issue was that i used a some 3 party stuff in my code and it was loaded via Vendor/autoload.php which couldn't be found

PHP Fatal error: Uncaught Error: Class 'PHRETS\Configuration' not found in /var/www/html/PHRETS/retsphp.php:107

so i had to edit that as well to be the full path. After making all these changes it now runs fine. So hopefully that will save someone else some time chasing down a similar issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.