Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I'm running a CentOS 5 server, and trying to schedule a job which runs a php file every day at the same time, I've added a new file to the directory

/etc/cron.d/

called get_files

The get_files file contains the following:

03 6 * * * php /var/www/html/get-info.php

However, the above job doesn't seem to get run. What am I doing wrong?

share|improve this question

marked as duplicate by Iain Apr 6 '13 at 17:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
That is an excellent canonical answer. It probably covers every cron-related question we've ever had here. –  Ladadadada Apr 6 '13 at 17:55
    
@Ladadadada: It is now, the $original was full of $fail. –  Iain Apr 7 '13 at 16:33

2 Answers 2

up vote 1 down vote accepted

you should use the full path to php, and use the -f switch

03 6 * * * /path/to/php -f /var/www/html/get-info.php
share|improve this answer

The cron jobs in /etc/cron.d/ (and also /etc/contab) have six parts before the command, not five. The first five are as you expect, the schedule. The sixth is the user the command should run as.

Cron files often have explicitly set variables such as SHELL and PATH which avoids requiring full paths to everything in the rest of the cron file.

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
03 6 * * * root php /var/www/html/get-info.php

Your original cron job would have been logging an error in /var/log/cron saying that it couldn't find the user "php".

share|improve this answer
    
+1, nice catch. –  David Houde Apr 7 '13 at 5:51

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