AUTHOR:         Jim Gifford <lfs-hints at jg555.com>

DATE: 		2003-10-22

LICENSE: 	GNU Free Documentation License Version 1.2

SYNOPSIS: 	Setup vixie-cron for LFS

DESCRIPTION:	This will describe on how to setup vixie-cron for LFS.

PREREQUISITES:	NONE

HINT:

Introduction to vixie-cron

Download location for vixie-cron
			ftp://ftp.roedu.net/pub/mirrors/gentoo.org/distfiles
vixie-cron Version used		3.0.1

cron is a standard UNIX program that runs user-specified programs at
periodic scheduled times. vixie cron adds a number of features to the
basic UNIX cron, including better security and more powerful configuration
options. 

---
Required Patches for vixie-cron

In order to build vixie-cron, you will need to patch it. I have made patches
available and posted to patches.linuxfromscratch.org. The patch order listed
is critical to follow. At this point I have assumed that you have downloaded
the vixie-cron-3.0.1.tar.bz2 file and uncompressed it.

Patch Order

Patch 1 - vixie-cron-3.0.1-redhat-mdk-1.patch
Patch 2 - vixie-cron-3.0.1-security-1.patch
Patch 3 - vixie-cron-3.0.1-makefile-1.patch
Patch 4 - vixie-cron-3.0.1-variables-1.patch

Optional - PAM

Patch 5 - vixie-cron-3.0.1-pam-1.patch

These patches can be retrieved from
http://www.linuxfromscratch.org/patches/downloads/vixie-cron
or
ftp://ftp.jg555.com/pub/patches/vixie-cron

All patches can be installed using patch -Np1 -i NAME

---
Install vixie-cron by running the following commmands|

make CC="gcc $CFLAGS" &&
make install

----
How-to use vixie-cron

The cron daemon consults so-called crontabs for jobs to execute. These
crontabs are ordinary textfiles, however you should always use the crontab
tool to manipulate them.

To have a look at your crontab execute crontab -l. If a crontab exists then
it's contents is listed, otherwise "no crontab for <username>" will be
displayed.

To add or delete an entry in your crontab, use crontab -e. Which editor is
used can be customized, but usually it's vi or whatever is in EDITOR variable.

You add or delete entries by adding or deleting the appropriate line in the
crontab (every entry takes exactly one line).

Each line consists of six columns which are seperated by blanks. The sixth
(rightmost) column tells cron which command/file to execute (always use the full
path here), while the other five columns tell cron when to execute it.

The columns (1 stands for the leftmost column, counting to the right) have the
following meaning and take the values in brackets: 

Minute (0 - 59)
Hour (0 - 23)
Day of month (1 - 31)
Month (1 - 12)
Day of the week (0 - 6, 0 representing sunday, 6 saturday) 

In each of these five columns an asterisk ("*") stands for "every". 
Example: "41 5 * * * /home/jim/backupmeup.sh" would mean that everyday at 5:41
in the morning the script backmeup.sh in jim's home directory would be executed
(assuming, of course, that the script is executable).

If you want to specify a group of times, then concatenate the individual values,
seperated by commas (Example: "00,15,30,45" - in the first column this would read
as "every quarter of an hour on the quarter of the hour").

If you want to specify a range of times, you can use the minus (Example: "1-5"
in the fifth column would read as "every workday"). 

---
/etc/cron.d

You can also create text files with the same information listed above in /etc/cron.d.
When you add a file to this directory, crond will sense the addition and add it to the
execution schedule.

---
/etc/crontab


---
Make cron start on bootup

Create the /etc/rc.d/init.d/cron by running:

cat > /etc/rc.d/init.d/cron << "EOF"
#!/bin/sh
# Begin $rc_base/init.d/cron - cron loader

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
	start)
		echo "Starting Cron Scheduler..."
		loadproc crond
		;;
	stop)
		echo "Stopping Cron Schedular..."
		killproc crond
		rm -f /var/run/crond.pid
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	status)
		statusproc crond
		;;

	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/cron
EOF

---
Make the script executable and create the appropriate symlinks by
running:

chmod 755 /etc/rc.d/init.d/cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc0.d/K08cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc2.d/S40cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc3.d/S40cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc4.d/S40cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc5.d/S40cron &&
ln -s /etc/rc.d/init.d/cron /etc/rc.d/rc6.d/K08cron

VERSION:        1.1

CHANGELOG:     	1.1 Fixed Typos (Thanx Thomas Trepl)
		1.0 Initial Version

 New Version of this document can be viewed from http://cvs.jg555.com/viewcvs.cgi/lfs-hints


