CRON; (c) Kees Lemmens, July 1993 ; Version 1.1
-----------------------------------------------

This software may be redistributed in the Public Domain under the folllowing
conditions :

- It may not be used for commercial purposes.
- Distribution should always contain all files in this archive.
- If you make any modifications, you're not allowed to redistribute these
  modifications without my permission.
- It may not be sold, unless it is for a nominal fee just to cover the dis-
  tribution costs.

DISCLAIMER :
------------

- You're using this program completely at your own risk ! I am not worried
  about big bugs in this cron, but I know the laws in the VS are absolutely
  crazy about these matters. Thank God (and I tell you I'm a pure atheist)
  we don't have such stupid laws here in Holland !

Well that was the official part !

VERSION 1.1: A few bugs fixed and new functionality added ; AT command
VERSION 1.2: User and group id's now supported. Current dir is changed
	     to homedir before starting job.
	     SIGHUP mechanism abandoned because it didn't allow other
	     access than root (uid 0). It is replaced with a command
	     pipe.
	     Lockfile isn't created anymore, as the commandpipe can be
	     used in the same manner.

DESCRIPTION
-----------

The CROND daemon runs on the background and is able to run many jobs
at specified intervals. Job output is sent as mail to the user.

The CRONTAB and AT programs are used to supply new tasks to the CROND daemon.

Behaviour is similar to the UNIX cron , crontab and at commands.

CROND:
------

Reads all crontab files in CRONDIR (usually /usr/spool/cron/crontabs)
and checks every minute by applying a bitmask from the current time
+1 minute on the timemasks of the jobs in the joblist to see if there
are jobs that should be started in the next minute.

If this is the case cron spawns these jobs with their output redirected
to a temporary file in SPOOLDIR.
It also checks every minute ( with the wait3 function ) to see if
there are finished jobs. If so, it sends their output together with 
the exit code as mail to the owner and then removes the temporary file.

System load could be less if we do not check every minute for the bit-
masks and finished jobs, but it takes so little time (approx. 10-20
milliseconds on my 16 MHz STE), that you virtually won't notice cron
is running as long as there are no jobs to be started.

Default priority for all cron processes is -5 (NICELEVEL) so this also
helps to prevent system overload.

The current shell is Mintshel. You can change this easily into KSH or TCSH
but then every job wil take much more time and system load, because these
shells are much bigger than Mintshel. I think it's better to start your
own shell from the Mintshel only if you need its possibilities.

Remember the Mintshel can also start batchjobs with the extension .bat !!
 
Files/dirs necessary to run cron :

- SPOOLDIR      (/usr/spool/cron: used for output files)
- CRONDIR       (/usr/spool/cron/crontabs: to store the crontabs)
- ATDIR         (/usr/spool/cron/atjobs: to store at jobs)
- /etc          (used for the crond.pid file)
- /etc/passwd   (fron crontab to check if username exists)
- /usr/mail     (this is where it puts the output from the cronjobs)
- /bin/mintshel (in /bin : cron uses 'mintshel -c' to start jobs)
- /bin/cat      (cat is used to append the job output to the mailfile)

Files that are created :

- /etc/syslog is automatically created if it doesn't exist. All messages
  and errors will be written to this file. Change LOGFILE into something
  else if you want your messages to go to the console or another logfile.

- /etc/crond.pid contains the process id of the running daemon. This is 
  being read by the CRONTAB command to force a reread of the crontabs 
  (by sending a SIGHUP signal) when something has changed.

- /usr/mail/<user> files to send output to the user.

It is best to start cron from your mint.cnf file, so it will run always
in the background as soon as your machine starts up.

CRONTAB :
---------
	
This program is only a user interface to the CROND daemon that should
run on the background of your ATARI to make things work.

Syntax:
	crontab -l         : list existing crontab
	crontab -r         : remove existing crontab
	crontab <filename> : replace crontab with a new one

If your userid (LOGNAME) is not set, you can force a username with the
-u <user> option.

Crontab does 3 things when creating a new crontab :

- It checks your new crontab for syntax errors.
- It copies the new crontab to the crondir , which is often
  /usr/spool/cron/crontabs.
- It sends a rebuild signal to the cron daemon to make it reread
  the crontables from disk.

Syntax of a crontab line :

<MIN> <HOUR> <DAY> <MONTH> <WEEKDAY> <SHELL COMMAND>

All timefields can be supplied in one of the following ways :

*              All possible values of this field are valid.
<nr>[,<nr>,..] A number for every timevalue you want the command to be
               executed.
<from>-<to>    An interval for the times you want to the command to run.

Combinations are not allowed, so either *, or ..,.. or .-.. !!

Valid ranges :

MIN     : 0-59	HOUR    : 0-23	DAY     : 1-31
MONTH   : 1-12	WEEKDAY : 0-6 (0=Sunday)

Shell commands can be supplied in UNIX format. They will automatically be 
rewritten to TOS format. (/ changed into \)

Example :

0 11 * * 3,6 /bin/mv -f /etc/syslog /etc/syslog.old

This entry will move the syslog file twice a week to syslog.old : Every
Wednesday and Saturday at 11:00 AM.

AT:
---

This tool can start a job for one run in the background at a specified time.
Behaviour is similar to the UNIX AT command, but the code was completely by
myself.

Syntax:
	at -l         : list existing at jobs
	at -r <nr>    : remove at job <nr>
	at <timespec> : submit a new at job (command is read from stdin)

There are 3 possibilities to specify the time :

- at now + 12minutes	at now + 3hours,
  at now + 2 days	at now + 1 week
 
  As you see you can omit the space between the timevalue and type.
  
- at 12:30

  If the time is earlier than the current time the job will run
  next day at the specified time.

- at 12:30 27-3

  If the time is earlier than the current time the job will run
  next year at the specified time.
  
The shell command is read from stdin. Any CR, LF or Ctrl-D will finish
the command and submit the job to the Crondaemon.
In this way it is also possible to use a pipe and echo to specify the
command (only from a shell !):
  
  	echo '/bin/ls -la' | at now + 2days

Remark:

The only valid symbolic time is 'now'. So names like 'tomorrow', 'midnight'
and others that can be used on some UNIX systems are not allowed.

------------------------------------------------------------------------

CRON can be used to perform backups, to clear all kinds of log files, to 
make your ATARI autmatically collect mail from a mailserver by telephone,
to play a tune on your synthesizer every hour and everything else you can
think off !

WARNINGS :
----------
  
- AT and CRONTAB programs can only run if the CROND daemon is running in
  the background of your (MULTITOS) ATARI.
- The files at.allow, at.deny, cron.allow and cron.deny are not implemented
  as I consider this useless on a simple ATARI.
- The programs need a passwd file to check the username (which is read
  from LOGNAME env variable, uid or from the cmdline option -u <user>).
- Combinations of intervals and comma separated values in the crontab time-
  fields are not allowed !
- You may only start TOS or TTP programs from the Mintshell !
- The program doesn't know about crazy things like daylight savings time
  and so: if you start your program on a non-existing hour it simply won't
  run (presumed you adjusted the clock at the right time, which is of course
  possible with cron !!)

Any remarks or suggestions about these programs can be send to:
lemmens@dv.twi.tudelft.nl






