Crontab - doing things periodically

Dirk Koopman G1TLH

Last modified: Mon Apr 23 01:00:44 BST 2001


There are a number of jobs that need to be done periodically. The principle one being starting connections to other clusters if you are not connected. The crontab allows you to do this.


There two locations for the crontab files. The first and standard one (which in common with other 'issue' files should not be changed) lives at /spider/cmd/crontab. The sysop changable one lives at /spider/local_cmd/crontab.

The files will automatically be re-read whenever you change them.

The Crontab File

The crontab file defines what is to be done and when. It consists of lines of text created by your favorite editor. Completely blank lines or lines starting with '#' are ignored.

Each line of a crontab file contains six fields each separated with white space. The first five fields are times when the command is to be executed and the last field is the command itself. The time fields consist of:-

fieldAllowed Values
minute0 - 59
hour0 - 23
day of month1 - 31
month1 - 12
day of week0 - 6 (0 is Sunday)

A field may be '*', which means 'any when' for that field.

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an hours entry specifies execution at hours 8, 9, 10 and 11.

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: 1,2,5,9 or 0-3,5,8-12.

Commands are actually small snippets of perl. They can be anything legal within perl and the context of the DXSpider daemon. The normal use will be connecting to another cluster and a set of routines are specially provided in the context of the DXCron package to make this easy. For example

  start_connect('gb7tlh') unless connected('gb7tlh')
this could have also been written:
  start_connect('gb7tlh') if !connected('gb7tlh')
but the first method is more 'perlish',

Either of these commands will attempt to start a connection process to GB7TLH if it isn't already locally connected.

There is absolutely no reason why you could not do something more complicated using information contained inside the DXSpider daemon, but this will obviously require a more complex line of code. You can also write your own functions, include them within the DXSpider system and call them from the crontab

A full crontab file could like like:-

  # This is a sample crontab file 
  # check every 10 minutes to see if gb7tlh is connected and if not
  # start a connect job going

  0,10,20,30,40,50 * * * * start_connect('gb7tlh') unless connected('gb7tlh')

  # at 03:15 on Sundays start a job called '' which does something
  # or other. This starts a new process and runs to completion, be careful
  # what you do with stdin and stdout as they are the same as those of

  15 3 * * 0 spawn('/spider/local/')

  # this is a pointless command which will echo the string shown
  # on the same terminal as the program after substituting
  # the values for mycall and version
  15,30 * * * spawn("echo $main::mycall is a DXSpider Version $main::version DX Cluster system")

  # then there is always the highly contentious one like this little jem which
  # checks every hour to see if a certain callsign is connected to another cluster
  # and silently disconnects him. This is an example only (of course...)
  23 * * * * rcmd('rcmd/gb7dxm disc/noinform G9TLH') if present_on('G9TLH', 'GB7DXM')

  # some people like to do an hourly announce to say who they are. There is a 
  # slight complication about this because of the announce duplicate checking
  # so you need to make each announce unique. I do this by adding a date and time
  # stamp on the end

  0 * * * * run_cmd('ann CLUSTER: GB7DJK JO02LQ at ' . cldate . ' ' . ztime)
It is important remember that these crontab routines execute in line with the main cluster code, so if you create a long, slow crontab command, it will impact on the speed and usability of the cluster as a whole.

If you want to see what commands are being run and/or the syntax errors in the crontab, then run: set/debug cron on the console and monitor the debuging output (I use watchdbg in another window).

To set the debugging back to normal do: unset/debug cron.

Standard Routines

As mentioned earlier, there are a small number of routines that are declared in DXCron context. They are there basically to make the starting of connections and external programs easy. They are:-


Copyright © 1998 by Dirk Koopman G1TLH. All Rights Reserved