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

I've put two files in the /etc/cron.d/ directory:

The first makes a new post everyday at 12:00AM:

0 0 * * * php /var/www/site1/helper post:make

The second updates the latest post every 10 minutes

10 * * * * php /var/www/site1/helper post:update

Do I have to do something else for this job to run based on the time (eg. every 10 minutes) or do I have to do crontab job1 and crontab job2?

EDIT: I also installed cronie.

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

Putting files in cron.d is enough. However, your last entry should be:

*/10 * * * * php /var/www/site1/helper post:update

Otherwise it runs once an hour, at the 10th minute.

share|improve this answer
    
Oh wow thank you for correcting :) –  Pineapple Under the Sea Jun 14 '12 at 10:03
    
And as mentioned below, add a user. I didn't look closely enough and thought php was your user :) –  Halfgaar Jun 15 '12 at 12:24
add comment

Also, add

> /dev/null 2>&1

at the end (after the command) so the cron won't spam you with outputs :)

share|improve this answer
    
how will it spam me with outputs? thanks. –  Pineapple Under the Sea Jun 14 '12 at 10:30
3  
The output of cron jobs goes to the mail box of the user it was running as by default. If you haven't configured your mail server or added something to /etc/aliases, these will end up in /var/spool/mail/<username>. Eventually, they will fill your filesystem... which is bad. –  Ladadadada Jun 14 '12 at 10:34
1  
Exactly :) It is very interesting when you create a 1 or 2 minute crons and you open your mailbox after 2 days :) –  mangia Jun 14 '12 at 10:36
    
Oh I didn't know that, It currently has 280 lines. Thank you! –  Pineapple Under the Sea Jun 14 '12 at 10:45
2  
Only put that on the end of the line after you have tested it to ensure it's working correctly, otherwise it won't tell you if there is a problem. –  John Gardeniers Jun 14 '12 at 16:01
show 2 more comments

The crontabs in /etc/cron.d/ require a username in the 6th field, as does /etc/crontab. User-based crontabs in /var/spool/crontabs/ and via crontab -e do not have a username field.

Halfgaar's answer about the timing of the one that runs every 10 minutes is also correct.

Currently, these cron jobs execute /var/www/site1/helper as the php user rather than executing /usr/bin/php and passing it the arguments /var/www/site1/helper post:make. This will work if your have a php user, the file is executable and has an appropriate shebang. (i.e #!/usr/bin/php as the first line.) Otherwise, it will log an error in /var/log/cron/log.

The example below runs them as the httpd user and has an explicit path to the PHP executable. You should choose an appropriate user.

0     0 * * *  httpd /usr/bin/php /var/www/site1/helper post:make
*/10  * * * *  httpd /usr/bin/php /var/www/site1/helper post:update
share|improve this answer
    
can I run it as a root user instead? Oh and Yeah I checked var/log/cron and it has a line about invalid username. –  Pineapple Under the Sea Jun 14 '12 at 10:31
2  
You certainly can. Choosing a different user is part of the principle of least privilege. If it doesn't require root, don't use root. –  Ladadadada Jun 14 '12 at 10:32
    
Thank you Ladada –  Pineapple Under the Sea Jun 14 '12 at 10:33
add comment

This:

10 * * * * php /var/www/site1/helper post:update

Will not run every 10 minutes, it will run at minute 10 of every hour (00:10, 01:10, ...).

This will run every 10 minutes:

*/10 * * * * php /var/www/site1/helper post:update
share|improve this answer
    
thank you so much @faker –  Pineapple Under the Sea Jun 14 '12 at 10:04
add comment

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.