0

I need to run a CRON each 5 minutes for a specific user example.com, the script executed is a php file.

File : /var/spool/cron/crontabs/example.com

/5 * * * * /usr/bin/php -f /home/example.com/public_html/cron.php

Nothing happens (no error in log, no error mail, nothing). Same when testing with :

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php -f /home/example.com/public_html/cron.php

Of course running the file manually works. Also, changing the CRON every minutes works :

* * * * * /usr/bin/php -f /home/example.com/public_html/cron.php

When trying the same start timing (5 minutes) but as root, it is running perfectly (/var/spool/cron/crontabs/root instead of /var/spool/cron/crontabs/example.com).

I've tested on Slackware 12.0 and Slackware 14.0... same problem.

  • Are you installing the new crontab with `crontab -e` which checks the format for problems? Or, are you accessing the file directly with you editor? – John1024 Oct 09 '14 at 04:53
  • @John1024 file editing with `vi` or with `webmin` (tested both). Also tested `crontab -u example.com -e`... no more luck. – Alexandre Lavoie Oct 09 '14 at 18:34
  • If this command is the last line in the crontab file and it has no carriage return at the end it will not run. This is just a shot in the dark but I have had it happen in the past and spent hours trying to figure out the problem and all it was, was I didn't hit ENTER at the end of the line. Weird I know but it happened to me. – Widgeteye Oct 22 '15 at 19:48

1 Answers1

0

crontab -e tells me that this is an error ("bad minute... errors in crontab file, can't install"):

/5 * * * * /usr/bin/php

On the other hand, it accepts and runs the program every 5 minutes:

0-59/5 * * * * /usr/bin/php

This is also accepted and the program runs every 5 minutes:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php

How to use crontab -e

crontab -e will open current crontab using the editor specified by the VISUAL or EDITOR environment variables, if one exists, or /usr/bin/editor is neither exists. After editing but before installing the revised file, it checks the format and, if problems are found, issues errors and offers to let you either re-edit the file or quit leaving crontab unchanged.

Common problems with cron

A community wiki with much information on common problems with cron is:

John1024
  • 16,593
  • 5
  • 50
  • 45
  • Well I probably made a mistake with `/5` but I ommited to say that I tested `*/5` also. The point is that `0,5,10,...` is valid, but ONLY working if used in the root file (so runned as root). When used in the website user file, it will work one or two times and nothing else... – Alexandre Lavoie Oct 09 '14 at 18:36
  • They run fine for me as a normal user. What cron-related messages do you see in `/var/log` for messages? Do you have cron set up to send email in case of errors? – John1024 Oct 09 '14 at 20:55
  • It is configured to send email in case of error, but not email error nor logged error (/var/log/cron is empty). – Alexandre Lavoie Oct 09 '14 at 23:58
  • @AlexandreLavoie OK. If the log files have no info and the email system fails, we need to work harder. Try redirecting the stdout and stderr like this: `0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php -f /home/example.com/public_html/cron.php >$HOME/my.log 2>&1`. Also, as long as it is not working, use _only_ `crontab -e` to make changes to a crontab. – John1024 Oct 10 '14 at 05:49