Setting up crontab in Drupal
Not knowing so much about Unix commands and such setting up crontabs for your Drupal site can be a hassle. I recently noticed that my supposed crontab run wasn't functioning as expected. Patching together intelligence from several sites I finally managed to make something useful at last.
First create directory and the file that the crontab will call, in my case it was put in a bin directory on the same level as my public_html directory.
$ mkdir bin
$ cd bin
$ pico weekly.crontab.sh
We then write in the sh-file what we want to do with our crontab, in my case just calling the Drupal crontab and mailing the output of it; in my crontab I have some code that outputs some logging info.
#!/bin/bash
lynx -dump http://www.mysite.com/cron.php | mail myname@mysite.com
Lynx is a web browser that looks up the URL and the -dump command then catches all the output and mails to my mail address.
After saving I created the crontab file
$ chmod +x weekly.crontab.sh
$ crontab -e
and added the line
43 18 * * 7 ~/bin/weekly.crontab.sh
and saved my work. The line basically means will be run at 6:43pm every Sunday, easy enough.
And of course we check that it works by typing
$ ./daily.crontab.sh
Voila!