0

I have a PHP file that is suppose to send one email per day scheduled by crontab. Here is my crontab:

45 23 * * * php /var/www/html/linus/class/runnable/dailyStaffReport.php

I noticed that it's not working, that is, the email is not being sent. So I tried the following:

00 11 * * * php /var/www/html/linus/class/runnable/dailyStaffReport.php 
            >> /var/log/crontab.linus.log 2>&1

Note: the time schedule here is not important, I'm constantly changing it for the testing purpose

That did not work. The file crontab.linus.log was not created.

While checking the /var/log/cron file, I noticed that my cron is executed

Feb 25 11:22:01 shoutcast01 CROND[3395]: (apache) CMD (php 
    /var/www/html/linus/class/runnable/dailyStaffReport.php 
    >> /var/log/crontab.linus.log 2>&1)

And lastly, if I manually execute php /var/www/html/linus/class/runnable/dailyStaffReport.php I get the email right away in my inbox. I even wrote some echoes in the PHP script in the hopes to try and see if somewhere along the line the script fails.

[root@shoutcast01 ~]# php /var/www/html/linus/class/runnable/dailyStaffReport.php
  LOADING STAFF USERS...
  COMPUTING STAFF WORK TIME...
  BUILDING CHART...
  SAVING CHART...
  WRITING DOWN THE CHART...
  SENDING THE EMAIL...
  1
  DONE.

On a simular matter, I have another file that is scheduled to send emails every 2 minutes and it works perfectly.

[root@shoutcast01 ~]# crontab -u apache -l
22 11 * * * php /var/www/html/linus/class/runnable/dailyStaffReport.php 
      >> /var/log/crontab.linus.log 2>&1
*/2 * * * * php /var/www/html/linus/class/runnable/dispatchEmail.php 

To sum up

  • The email gets delivered if I execute the script manually in the terminal.
  • the email does not gets delivered, but cron log tells me the script was executed.
  • I'm unable to log anything with >> /var/log/crontab.linus.log 2>&1

Any tips on what I can do to try and solve this problem?

0

The problem that debugging wasn't working was that I was trying to store the debug information into /var/log/crontab.linus.log and that file didn't exist and the user apache did not have permission to create it.

After realizing that, I created the file myself

touch crontab.linus.log
chown apache crontab.linus.log
chgrp apache crontab.linus.log
chmod 0777 crontab.linus.log

Then I scheduled the task again and waited for it to be executed. Turns out, the original problem was also about permission.

PHP Fatal error: Uncaught exception 'ImagickException' with message 'Unable to write the file [...]

So I set chmod 0777 in the foloder that the PHP script saves it's images. After that the schedule being executed by apache user was successfully executed and the email was sent.

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.