How to set cron for a drupal site
So you've got yourself a drupal site and you're super tired of running cron by hand every day, or every time you want to refresh your news feeds or whatever...
Maybe you like running cron manually all the time, if so, stop reading now and go get a muffin...
Resolution
Anyway, here's how to do it in a few easy steps, aka the agaric way...
First, go to your command line and type:
sudo crontab -l
That'll show you what's already scheduled to run...
Then, type:
sudo whereis wget
To confirm the location of wget --> probably, /usr/bin or something
Finally, type:
sudo crontab -e
This will open up a file and you'll probably see at least a line showing you the proper syntax for running cron...
anyway on a new line for each site you want to run cron on, use this:
45 * * * * /usr/bin/wget -O - -q http://www.example.com/cron.php
Make sure you save the file with ctrl+O then hit ctrl+x to exit..
Thats it! cron will run at 45 minutes past the hour on every site you setup...
Referenced:
http://drupal.org/node/31549
http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/
Comments
Awesome Dan! A user
Awesome Dan!
A user interface someday to look and maybe set what cron we have for every site, but
crontab -l
(that's a lowercase L if you aren't copy-pasting) sure isn't hard.We do want to be able to set cron from a bash script, Agaric's addsite script. Crontab seems to be an actual file (can't find it though) so there should be a way to pipe output to be added to the end of it... (to be continued)
And the
whereis
command is so much better thanlocate
at actually finding what you need! Great work Dan!how to tell cron to run on a
how to tell cron to run on a file on the server?
Dan Hak: i assume you can tell cron to run whatever command you want on a recurring basis
I3IVIIVI: do you remember what's typed? or if you documented? just to get into cron?
Dan Hak: yea I documented that I m sure
[Agaric's page here didn't answer, but]
I3IVIIVI: bloody hell we just have to put it in the directory labeled "hourly"
more good info
Run command at 7:00am each weekday [mon-fri]
00 07 * * 1-5 mail_pager.script 'Wake Up'
Run command on 1st of each month, at 5:30pm
30 17 1 * * pay_rent.script
Run command at 8:00am,10:00am and 2:00pm every day
00 8,10,14 * * * do_something.script
Run command every 5 minutes during market hours
*/5 6-13 * * mon-fri get_stock_quote.script
Run command every 3-hours while awake
0 7-23/3 * * * drink_water.script
do it! the agaric way... (example below)
Run cron every 5 minutes...
*/5 * * * * /usr/bin/wget -O - -q http://www.example.com/cron.php
got it?
good.
Thanks a lot!
Just wanted to drop a line to thank you for posting this tip, and the many examples!
Cheers!
~Nick
why the sudo???
You don't need to run cron as sudo/root, any user can have cron jobs running (this is good to know if you don't own your own server -- most people don't...)
Here's what I do:
$ crontab -l
$ which wget
/usr/bin/wget
$ crontab -e
Two more points:
1.
whereis
will show you all locations of wget,which
will show you the version of wget that you run when you as that user type "wget" now.crontab -e
opens the editor set in your $EDITOR environment variable. On your setup, it seems this was nano (ctrl+O saves), on mine, it was vi (:wq saves and exits, a bit more complex program). DoEDITOR=nano && crontab -e
to make sure you use nano (etc. for emacs, vi, ...)WAMP?
I'm pretty new to Drupal so I love your simplification, but what about Windows/WAMP users?
Thanks for the examples
Nice and clear. Examples are sometimes better than reading the full docs and trying to guess at the syntax.
I found that our sysadmin on a system I'm taking over had the crontab instructions in a slightly different place. Normally I'd use the
crontab -e
method, but after grepping/etc/cron/
I discovered a file inside/etc/cron.d/{sitename}
where the cron instructions were.
FYI, for debugging & analysis, you can check the status of cron on your site at
/admin/reports/status
(you probably should know that), but for even more detail, I had to do something likesudo grep cron /var/log/apache2/{sitename}_access.log
where I found evidence that cron really was running regularly.
Post new comment