Skip to content Skip to navigation

Instructions for the dedicated grizzled technologist

Topics: 
Tags: 

Note: The Scheduling Service is now live at http://tools.stanford.edu (look under Web Services, Scheduling Service) and it's a much easier way to accomplish the goals outlined below.

cron jobs are created from the (unix) command line with the *crontab* command.

Documentation within the Drupal.org site is woefully confusing, but is helpful in that one quickly realizes that everyone finds crontab difficult. Here are the most common solutions (outside Stanford) none of which require messing with crontab:
* ISP handles this for their client
* admins set this up using cpanel
* poor man's cron module (Drupal) [http://drupal.org/project/poormanscron]
* use of wget instead of cron

Instructions below are for the dedicated grizzled technologist who wants to setup their own crontab on Leland (by god\!)

Background reading

* [http://drupal.org/node/1181] \- read this to comiserate with others having problems
* [http://drupal.org/node/31549] \- this is actually useful
* *man crontab* from a Unix shell

What the cron job does

* crontab creates a crontab file that runs a script on a regular time interval (cron = chronograph)
* in the case of Drupal, this calls a file *cron-lynx.sh*
* cron-lynx.sh is a shell script that uses the lynx web browser to ping your site's cron.php which indexes the site, and keeps various contrib modules happy
* Cron does things like re-building the index of the database. Some modules use cron to update their information, call APIs etc.

contents of the cron-lynx.sh file:

\#\!/bin/sh
/usr/bin/lynx \-source [http://example.com/cron.php] > /dev/null 2>&1

Changes need to be made to this file
* the path to lynx needs to be changed to the Stanford specific path: /usr/pubsw/bin/lynx (you can verify the location of lynx by typing *which lynx* at the shell)
* the location of the cron.php needs to be changed

example cron code

* 00 * * * * /path/to/scripts/cron-lynx.sh

setting up crontab

* option 1: type *crontab \-e* from command line and type cron code (1 line in this case) directly into the text editor that launches
* option 2: load cron job from file (ZC: this is what I did, seems safer) refer to drupal.org link above

Permissions

* once your crontab is set, you may need to fix permissions so that the crontab "user" can access cron-lynx.sh
* the cron job will be run as you (i.e. the user that typed *crontab \-e*)
* if cron-lynx.sh is installed in AFS space, even though the cron job runs as you, it will not have access to the AFS credentials necessary to read the file (and you won't know an error occurred because output is discarded by the command in cron-lynx.sh). So, the simplest solution is to make cron-lynx.sh executable and place it in a directory that is readable by system:anyuser. Obviously, don't put any other files in there and nothing of a sensitive nature. Better yet, use JRJ's instructions below which bypass AFS issues and use wget which is more lightweight than lynx.