Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Im trying to run a PHP script, once a day, on ubuntu 13.10 server with php5.

I have cron jobs set up, via ajenti control panel, verified with crontab -l, for this command.

php /path/script.php site_id=2 table=clicks

I have been adjusting the time while trying to get it to run, but basically I want to run it at 2am.

0 2 * * * 

I have tried running the script directly, running it via /usr/bin/php, /usr/bin/php5/, and php, and nothing ever leaves a trace in syslog, or the apache log or error files (trace level 8)

I was trying to run it at 2am, so I set it that way, but running a date on the terminal shows the current time as

Thu Feb 6 07:44:29 UTC 2014

I have tried running the cron jobs at 7something am too, and again, nothing runs.

Any ideas? Besides syslog, is there any ubuntu logging for cron jobs, to see if they run or don't and why?

Also, is that the proper way to send arguments? Does the script need to accept them any differently than a web based script?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

First, validate your command works properly from command line:

/usr/bin/env php /path/to/script.php arguments

Second, validate your cron is running:

ps auxw | grep cron

There should be line like (highlights with ^ mine)

root      1537  0.0  0.0  19112   336 ?        Ss    2012   1:03 cron
^^^^                                                             ^^^^

If cron is running properly, check other cron messages from syslog:

sudo zgrep CRON /var/log/syslog*

By default, various tasks run as root, configured in /etc/cron.daily, /etc/cron.weekly etc. folders. If there's no output, your cron is not running properly. Try restarting it with

sudo /etc/init.d/cron restart

And check contents of /var/log/syslog for error messages, and proceed to step 1 again


If cron is running properly, proceed to check mailbox of the user that has that command on their crontab. Replace USERNAME.

sudo -u USERNAME mail

or sudo -u USERNAME less /var/mail/USERNAME

If executing cron command fails, it should send email to there.


You should use /usr/bin/env php /path/to/script.php as your command, instead of just php. /usr/bin/env automatically selects proper php binary.


For arguments, no, you have to read arguments separately. That's off-topic for this site, but take a look at this manual page. You can read those arguments from $argv. It does not work in same way as with scripts called through web server.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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