Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

Cron: Not working

OS: Centos 5.4/Plesk

When I run:

#php -q /var/www/vhosts/website.com/httpdocs/cron.php

cron.php sends me an email.

When I add the following to /etc/crontab - nothing happens.

0-59/1 * * * * php -q /var/www/vhosts/website.com/httpdocs/cron.php

or

*/1 * * * * php -q /var/www/vhosts/website.com/httpdocs/cron.php

I tried restarting the cron daemon but still nothing.

What am I doing wrong?


0
AdrianSmithUK
Asked:
AdrianSmithUK
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
woolmilkporcCommented:
Use the full path to php, e.g. /usr/local/bin/php

Use full paths inside the php script as well, because cron does not run the user's initialization profile, so there will not be the usual environment.

wmp
0
 
farzanjCommented:
Why are you doing */1?

crontab -e -u <USERID>
Could you try
* * * * * /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

Also see the cron daemon status

service crond status
0
 
KalpanCommented:
please modify your cron entry as below

0-59/1 * * * * wget -qb http://website.com/httpdocs/cron.php > /dev/null

please refer the below cron calculator to set the time

http://www.csgnetwork.com/crongen.html

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
AdrianSmithUKAuthor Commented:
Dear WoolMilkPork

I tried

*/1 * * * * /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

But still nothing. The PHP file just has:

<?php

mail('test@email.com', 'myTest1', 'myTest1');

?>

Any other ideas?
0
 
AdrianSmithUKAuthor Commented:
Dear farzanj

The crond service is running.

I tried

* * * * * /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

But still no joy.
0
 
AdrianSmithUKAuthor Commented:
Dear Kalmax

I tried

* * * * * wget -qb http://www.website.com/cron.php > /dev/null

But no joy I'm afraid.
0
 
farzanjCommented:
Next check if it is just this script or it would not schedule anything at all?  Try a simple command running every minute.

I have seen this kind of problem with sometimes invisible characters in the cron file.  So sometimes location of your line is also important.  Put it in the first line.  Just another check for weird problems.

Check the user cron file was created

cat /var/spool/cron*/<userID>

Do you see your file?

I would also check if the user has permission over this script to run it.
0
 
woolmilkporcCommented:
Could it be that your php.ini is in a non standard location (such as /usr/local/etc), and that you point to this location by means of the PHPRC variable?

If so, please note that this variable is not available under cron and you should either use

* * * * * PHPRC=/usr/local/etc /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

OR

* * * * * /usr/bin/php -c /usr/local/etc -q /var/www/vhosts/website.com/httpdocs/cron.php

Please note that "/usr/local/etc" is just an example for a possible location of php.ini.

wmp

0
 
woolmilkporcCommented:
OK,

I just realized that we're talking about /etc/crontab here - the system crontab!

The format of this table is different from the one of a user crontab. The sixth field must contain the userid under which the job is to be run.

* * * * * adrian /usr/bin/php -q /var/www/vhosts/website.com/httpdocs/cron.php

wmp
0
 
AdrianSmithUKAuthor Commented:
Many thanks chaps.

WMP was correct - It was the 6th field.

Kind Regards,

Adrian
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now