cron for unix-pc file 1 of 3

Donald Lashomb donlash at uncle.UUCP
Fri Dec 29 14:11:29 AEST 1989


For all who requested my cron program:

I am very flattered by the number of requests I recieved for a copy of the
cron facility I wrote.  This facility implements the at(1), batch(1) and
[user and superuser] crontab(1) commands.

I am posting it to comp.sources.unix and comp.sys.att for those of you who
want it.  If you do not have access to these groups, drop me a line, and
I'll try to email you a copy.

Merry Christmas to all

here's file 1 of 3

-Don		donlash at uncle.UUCP

#! /bin/sh"
# -------------------- CUT HERE ----------------------"
#! /bin/sh"
# This is a shar file.  To unbundle it, remove everything"
# above including the 'CUT HERE' line using your editor."
# Then type 'sh thisfile'.  Your shell will unbundle it."
echo "extracting Files (    234 chars)"
sed 's/^X//' <<'SHAR_EOF' >Files
X./Size
X./Files
X./Install
X./Name
X./README
X./Remove
X./allow.c
X./at.1
X./at.c
X./cron.1
X./cron.h
X./crontab.1
X./crontab.c
X./daemon.c
X./fifo.c
X./job.c
X./job.h
X./log.c
X./makefile
X./memlist.c
X./parsesched.c
X./parsetime.c
X./resched.c
X./version
SHAR_EOF
if test     234 -ne `wc -c <Files`
then
	echo "Files unpacked with wrong size"
fi
echo "extracting Install (   4796 chars)"
sed 's/^X//' <<'SHAR_EOF' >Install
X#   Install for the cron(1M) facility  4/89 D.Lashomb
X
XLOCAL=/usr/local
XBIN=/usr/local/bin
XLIB=/usr/lib/cron
XSPOOL=/usr/spool/cron
XDAEMONS=/etc/daemons
XSRC=$HOME/Filecabinet/SRC
XmySRC=$SRC/Cron
XDOCS=$HOME/Filecabinet/DOCS
XmyDOCS=$DOCS/Cron
X
Xcat <<END
XInstall for cron(1M) facility:
X
XAdding login cron to the passwd file!
Xif you don't want me messing with your
Xpassword file, stop me now.
X
XEND
Xecho "shall I continue y/[n]? \c"
Xcase "`line`" in
X[Yy]*)	:
X	;;
X*)	exit 2
X	;;
Xesac
X
X# find an unused uid
Xfor uid in 50 51 52 53 54 55 56 57 58 59 60 bad
Xdo
X	cut -d: -f3 /etc/passwd | grep $uid >/dev/null || break
Xdone
X[ "$uid" = "bad" ] && {
X	echo "can't find unused uid"
X	exit 1
X	}
X
X# find gid for "other"
Xgid=`grep "other" /etc/group | cut -d: -f3`
X[ "$gid" = "" ] && {
X	echo "can't find group 'other'"
X	exit 1
X	}
X
Xecho "cron:NONE:$uid:$gid:cron facility:/usr/lib/cron:" >>/etc/passwd
X
Xecho "compiling the programs"
Xmake all
Xmake clean
X
Xecho "making directories"
X[ -d $LOCAL ] || {
X	mkdir $LOCAL
X	chown root $LOCAL
X	chgrp users $LOCAL
X	chmod 0755 $LOCAL
X	}
X[ -d $BIN ] || {
X	mkdir $BIN
X	chown bin $BIN
X	chgrp bin $BIN
X	chmod 0755 $BIN
X	}
X[ -d $LIB ] || {
X	mkdir $LIB
X	chown cron $LIB
X	chgrp bin $LIB
X	chmod 0700 $LIB
X	}
X[ -d $SPOOL ] || {
X	mkdir $SPOOL
X	chown cron $SPOOL
X	chgrp bin $SPOOL
X	chmod 0700 $SPOOL
X	}
X[ -d $SPOOL/atjobs ] || {
X	mkdir $SPOOL/atjobs
X	chown cron $SPOOL/atjobs
X	chgrp bin $SPOOL/atjobs
X	chmod 0700 $SPOOL/atjobs
X	}
X[ -d $SPOOL/crontabs ] || {
X	mkdir $SPOOL/crontabs
X	chown cron $SPOOL/crontabs
X	chgrp bin $SPOOL/crontabs
X	chmod 0700 $SPOOL/crontabs
X	}
X[ -d $DAEMONS ] || {
X	mkdir $DAEMONS
X	chown root $DAEMONS
X	chgrp sys $DAEMONS
X	chmod 0750 $DAEMONS
X	}
Xfor i in $SRC $mySRC $DOCS $myDOCS
Xdo
X	[ -d $i ] || {
X		mkdir $i
X		chown $LOGNAME $i
X		chgrp users $i
X		chmod 0755 $i
X		}
Xdone
X
Xecho "moving the programs to their proper places"
Xmv cron $DAEMONS/cron
Xchown root $DAEMONS/cron
Xchgrp bin $DAEMONS/cron
Xchmod 0700 $DAEMONS/cron
X
Xmv at $BIN/at
Xmv batch $BIN/batch		# a link to at
Xmv cronjob $BIN/cronjob		# a link to at
Xmv crtabj $BIN/crtabj		# a link to at
Xchown cron $BIN/at
Xchgrp bin $BIN/at
Xchmod 4711 $BIN/at
X
Xmv crontab $BIN/crontab
Xchown root $BIN/crontab
Xchgrp bin $BIN/crontab
Xchmod 4711 $BIN/crontab
X
Xecho "Ok, let's setup the allow and deny files."
Xrm -f $LIB/at.allow
Xrm -f $LIB/at.deny
Xrm -f $LIB/cron.allow
Xrm -f $LIB/cron.deny
X
Xcat <<END
X
XYou can choose to let at(1) and batch(1) be used by
Xall, some or none of the users in the following ways:
X
X  1 - allow everybody to use at(1) and batch(1)
X  2 - allow only the users you name
X  3 - allow everybody EXCEPT the users you name
X  4 - let only the superuser use it
X
XEND
Xecho "pick a number-> \c"
Xcase "`line`" in
X"1")
X	> $LIB/at.deny
X	chown cron $LIB/at.deny
X	chgrp other $LIB/at.deny
X	chmod 0600 $LIB/at.deny
X	;;
X"2")
X	echo "enter blank name to end list"
X	while :
X	do
X		echo "enter allowed user's name-> \c"
X		read name
X		[ "$name" ] || break
X		echo $name >>$LIB/at.allow
X	done
X	chown cron $LIB/at.allow
X	chgrp other $LIB/at.allow
X	chmod 0600 $LIB/at.allow
X	;;
X"3")
X	echo "enter blank name to end list"
X	while :
X	do
X		echo "enter denied user's name-> \c"
X		read name
X		[ "$name" ] || break
X		echo $name >>$LIB/at.deny
X	done
X	chown cron $LIB/at.deny
X	chgrp other $LIB/at.deny
X	chmod 0600 $LIB/at.deny
X	;;
X*)
X	echo "ok, only the superuser can use it"
X	;;
Xesac
X
Xcat <<END
X
XYou can choose to let cronjob(1), crtabj(1) and
Xcrontab(1) be used by all, some or none of the users
Xin the following ways:
X
X  1 - allow everybody to use them
X  2 - allow only the users you name
X  3 - allow everybody EXCEPT the users you name
X  4 - let only the superuser use it
X
XEND
Xecho "pick a number-> \c"
Xcase "`line`" in
X"1")
X	> $LIB/cron.deny
X	chown cron $LIB/cron.deny
X	chgrp other $LIB/cron.deny
X	chmod 0600 $LIB/cron.deny
X	;;
X"2")
X	echo "enter blank name to end list"
X	while :
X	do
X		echo "enter allowed user's name-> \c"
X		read name
X		[ "$name" ] || break
X		echo $name >>$LIB/cron.allow
X	done
X	chown cron $LIB/cron.allow
X	chgrp other $LIB/cron.allow
X	chmod 0600 $LIB/cron.allow
X	;;
X"3")
X	echo "enter blank name to end list"
X	while :
X	do
X		echo "enter denied user's name-> \c"
X		read name
X		[ "$name" ] || break
X		echo $name >>$LIB/cron.deny
X	done
X	chown cron $LIB/cron.deny
X	chgrp other $LIB/cron.deny
X	chmod 0600 $LIB/cron.deny
X	;;
X*)
X	echo "ok, only the superuser can use it"
X	;;
Xesac
X
Xecho "putting source code in $mySRC"
Xln *.h *.c makefile version $mySRC
Xecho "putting manual pages in $myDOCS"
Xln *.1 README $myDOCS
Xchown $LOGNAME *.h *.c makefile version *.1 README
Xchgrp users *.h *.c makefile version *.1 README
Xchmod 0644 *.h *.c makefile version *.1 README
X
Xcat <<END
X
XThe installation of the cron(1M) facility is now
Xcomplete.  However you will have to reboot the
Xsystem in order to fire-up the daemon.
XEND
Xsleep 5
Xexit 0
SHAR_EOF
if test    4796 -ne `wc -c <Install`
then
	echo "Install unpacked with wrong size"
fi
echo "extracting Name (     40 chars)"
sed 's/^X//' <<'SHAR_EOF' >Name
XImproved cron(1M) facility by D.Lashomb
SHAR_EOF
if test      40 -ne `wc -c <Name`
then
	echo "Name unpacked with wrong size"
fi
echo "extracting README (  29859 chars)"
sed 's/^X//' <<'SHAR_EOF' >README
X
X/* ------------------------- NOTICE -----------------------------
X
X   at(1) batch(1) cronjob(1) crtabj(1) crontab(1) cron(1M)
X	(c) copyright April 10, 1989 by Donald Lashomb
X
X   This program is free.  Use it, modify it, copy it, give a copy
X   to a friend; I simply request the following provisions be observed:
X
X   1. My name as original author and this notice remain intact.
X   2. This program (or any modification of it) is not to be sold
X      for profit.
X   3. If this program is included in commercial products, there be
X      no charge for it.
X   4. This program must be distributed with source code.  Compiled-
X      only or binary-only distribution of this program is not allowed.
X      The administrator of any system that uses this program must have
X      full access to the source code.
X   5. If you enhance this program, discover a bug, have any comments
X      about it (or flames) please let me know.
X   
X   		Donald Lashomb
X   		Main Street
X   		Cranberry Lake, NY 12927
X
X   -------------------------------------------------------------- */
X
X
XCron(1M) is a facility that allows you to schedule commands that will be
Xexecuted at a later time.  At(1), batch(1) and crontab(1) are available
Xon many unix systems, but not the AT&T UNIX-pc; so I wrote my own.
XBatch(1) is just a special form of at(1) which executes commands "now"
Xat low priority.  Crontab(1) lets users have their own crontab files.  A
Xnew cronjob(1) command is included which allows you to repeatedly execute
Xjobs according to a schedule.  Also included is a new crtabj(1) command
Xwhich actually underlies the crontab(1) command, but has some usefulness
Xto the user.
X
XI made some improvements over the standard sysV facility (as I understand
Xit).  The manual pages explain this stuff better than I can do here, but
Xhere are some highlights:
X
X	*  the ability to specify a nice value, even neg for root
X
X	*  great variety of listing options
X
X	*  accepts names like Sun Mon etc in times, dates, schedules
X
X	*  security strictly enforced by real uid
X
X	*  new cronjob command runs like at(1), but repetitively like
X	   crontab.  I use this instead of crontab, it's more efficient.
X
X	*  crtabj command is what really does crontab
X
X	*  everything (almost) compatable with standard sysV versions
X
X                          ***************
X
XThe facility is implemented in two parts: the user commands and the
Xdaemon.  These programs communicate through FIFOs.  Heres how it works:
X
XThe daemon is started at boot-time and runs in the background.  The 1st
X	thing it does is check the spool dir to see if there are any
X	jobs already there, and builds its in-mem job list.  The jobnumber
X	is the same as the filename for all jobs.  The daemon then writes
X	any free jobnumbers into the JNUMBS fifo, and enters its main loop
X	of sleeping for awhile, waking up and checking the FNAMES fifo.
X
XThe user calls the at(1) command, specifying the time when the job should
X	be run on the command line.  At(1) obtains a jobnumber from the
X	JNUMBS fifo and creates a file of that name in the spool dir.  It
X	writes some special information, eg. user's current environment,
X	into the job file and starts to read its stdin.  Everything that
X	the user types upto a cntl-D will be written into the job file.
X	When the user finishes, at(1) marks the end of the job, closes
X	the file and writes its name (=jobnumber) into the FNAMES fifo.
X
XThe next time the daemon wakes up, it will find the filename in the FNAMES
X	fifo and add it to its in-mem job list.  It then checks that list
X	to see if any jobs are scheduled to run at that time.  If it is
X	time to run a job, the daemon forks off a process that reads the
X	job file and recreates the environment that existed at the time
X	the job was written by the user, and runs the job.  The daemon 
X	removes the job file and makes the jobnumber available again by
X	writting it into the JNUMBS fifo.
X
XI tried to make things upwardly compatable with the sysV version, at least
Xfrom the user's point of view.  The implementation is obviously different:
X
XsysV:				| my version:
X--------------------------------|-----------------------------------------
Xone FIFO and signals for commu- | two FIFOs  JNUMBS daemon-->user
Xnication between daemon & user  |            FNAMES user-->daemon
X				|
Xatjobs filenames are an encoded | atjobs filenames are the same as the
Xform of execution time          | jobnumber.  other jobs here too.
X				|
Xcrontabs filenames are users'   | crontabs filenames are users' uid
Xlogin name			| number
X				|
Xsecurity based on login name	| security based on uid and login name
X				|
Xmultiple crontabs per uid if	| only one crontab per uid
Xlogin names different?		|
X				|
Xfile /usr/lib/cron/queuedefs    | user can specify nice value each job
Xtells daemon nice value and how | MAXKIDS daemon parameter sets limit
Xmany jobs to run at one time	| on how many jobs to run at one time
X				|
Xcrontabs run with limited env	| crontabs restore full user environment
X				|
Xcrontabs implemented ????	| crontab creates a separate job for
X				| every line in every crontab file
X
X                          ***************
X
XLike sysV, if you want to change your crontab you have to do something
Xlike this:
X		crontab -l > temp	# get a copy of my current crontab
X		crontab -r		# remove it from cron's inventory
X		vi temp			# make the changes
X		crontab < temp		# re-submit it to cron
X
X                          ***************
X
XCRONJOB vs CRONTAB
X------------------
XCronjob is a new command that can do many of the same things that crontab
Xis used for.  Like crontab, its jobs run repetitively according to a user
Xsupplied schedule.  Where crontab limits you to a single command per time
Xschedule (I'm talking about a single line in a crontab file here), cronjob
Xallows you to do a whole bunch of commands per scheduled execution.  What
Xusually happens with crontab is that the command part of a crontab line
Xactually calls a shell script.  With cronjob the job *is* the shell script.
XI/O overhead is lower because it's one less file that has to be openned.
XCPU load is lower because one less process that needs to be spawned.  There
Xare disadvantages, of course.  For one thing, with crontab everything is
Xin one place, easy to find.  With cronjob you've got to search every job
Xto find the one you are looking for.  Another thing is that with crontab
Xyou can do one >/dev/null, with cronjob you've got to do this for every
Xcommand in the "script".
X
X                          ***************
X
XINSTALLING THE CRON(1M) FACILITY:
X
X	(1) add a user called "cron" to the system
X	(2) edit cron.h to change parameters (optional)
X	(3) compile the programs
X	(4) create the proper directories and files
X	(5) move the programs where they belong
X	(6) create and edit the allow and deny files
X	(7) reboot to get the daemon running
X
XNote: an Install script for the UNIX-PC is included with this package.
XI don't know what method you use for installing software on your system.
XDo you use the user agent?  If so, cpio all the files together, add an
X+IN suffix and click on it with the mouse.  From the shell, all you'd
Xhave to do is su to root and run the Install script.  Of course, you can
Xalways do the installation "by hand" if you want.
X
XWARNING - the Install script modifies your /etc/passwd file!
X	  this facility uses a login name 'cron' for its operations.
X
X
X(1) Edit your /etc/passwd file to add a user named "cron".  Login "cron"
X    should have an impossible password like "VOID", its home directory
X    should be /usr/lib/cron and its shell should be /bin/sh.  Its group
X    id should be the same as other daemons like "lp".  On my system this
X    is the gid for "other".
X
X(2) Some of the compile-time #defines in cron.h that you may want to
X    change are:
X
X	NUMBJOBS - This determines the maximum number of jobs that the
X	daemon can handle.  Each job takes up 12 bytes in the FIFOs.  In
X	no case should you specify more jobs than the FIFOs can hold.  I
X	set it 400, which seems reasonable to me.
X
X	GRAINULARITY - is the number of seconds that the daemon sleeps
X	each wake/sleep cycle.  The smaller the number the quicker the
X	daemon will see a newly enterred job, but also the more overhead
X	the facility places on the system.  It is set to 60 and probably
X	should stay that way.
X
X	CATCHUP - This is the number of seconds behind "now" that a job
X	can be and still get executed.  AT_JOBs older than this will be
X	automatically removed by the daemon.  The at(1) command will not
X	allow you to enter jobs older than this either.  This parameter
X	has a few twists to it.  When you are enterring a job using the
X	at(1) command, "now" is measured from when you first called at(1).
X	So if it takes you a long time to type in a job, it's possible to
X	have the job refused because it is past CATCHUP (GRAINULARITY is
X	is also taken into account).  Now the daemon is another story.
X	It is possible to get the daemon to execute jobs older than the
X	compile-time CATCHUP parameter.  When the daemon is started, it
X	checks its environment for a shell variable of the same name, and
X	will override the compile-time parameter if there is one.  Also
X	the daemon can be called with a numeric argument on its command
X	line which will override both the compile-time and environment
X	settings.  Here's the reason for this scheme:  Recall that the
X	daemon checks for old jobs in the spool directory when it starts
X	up.  You may want jobs up to, say, 24 hours old executed when it
X	first starts up, but only allow "future" jobs to be enterred with
X	the at(1) command.  So you compile with CATCHUP #defined as 0,
X	but start the daemon with CATCHUP=86400 in its environment.
X
X	MAXKIDS - The daemon will only run this number of jobs on each
X	cycle.  If there are more jobs than this ready, they are pushed
X	ahead to the next cycle.  I #defined this to 10 for compiling.
X	Of course the more jobs the daemon runs at one time the more load
X	it puts on the system.  If you set this parameter too high, the
X	kernal will impose a limit, because it won't let the daemon have
X	any more processes.  Like CATCHUP, the compiled-in value of this
X	parameter can be overridden by using an environment variable or
X	command line argument when starting up the daemon.
X
X	MAXTRIES - Even if the daemon is successful in forking a process
X	to run a job, the system may fail to execute it because the owner
X	of the job is at his/her process limit.  The process will sleep
X	for 10 seconds and try again up to MAXTRIES number of times.  I
X	#defined this as 5 tries, seemed reasonable to me.  The 10 second
X	value is buried in the daemon's code, but it's not hard to find.
X
X	ZEROSECS - If this parameter is #defined, the schedule times you
X	enter with the at(1) command will have their seconds field set
X	to :00.  If it's not #defined, the seconds will be whatever the
X	current clock time's seconds are.  Having seconds = :00 seems
X	more intuitive.  Either way "at now" always uses the current 
X	clock time's seconds (otherwise it would be non-deterministic).
X
X	TZOVRIDE - If this parameter is #defined, the daemon's value for
X	the TZ environment variable will replace the user's value when
X	the job is run.  The reason for this is obscure, but here goes:
X	The environment variable TZ is used to determine whether daylight
X	savings time is in effect at a particular time.  The date of when
X	d.s.t. goes in effect used to be the last Sunday in April, and
X	this is the date compiled into the kernal and standard library.
X	The U.S. Congress has changed the date to the *first* Sunday in
X	April.  If you reset the system clock to compensate, the seconds
X	since Jan 1, 1970 GMT values of all your files and schedules will
X	be wrong.  So what I do is change the timezone instead.  But the
X	value of TZ in a user's job reflects what it was when the job was
X	created, not what it is when it gets executed.  By using TZOVRIDE
X	the TZ variable will get set to the value the daemon gets when it
X	is booted.  This will make things make things work right.
X
X	SET_LOGNAME - Normally the at(1) ... crontab(1) commands demand
X	that the LOGNAME environment variable be set correctly.  If this
X	parameter is #defined, the superuser (ie uid=0) gets "LOGNAME=root"
X	put in its environment whenever the usual LOGNAME check fails.
X	This allows you to "su" and use the commands.  Otherwise, you'd
X	have to login as root, use "su -", or setup LOGNAME by hand.
X
X(3) Compile the programs.  Just say "make" or "make all".  I've included
X    a simple makefile with these programs.  I usually compile with the
X    optimizer on, link with the shared library and strip the object files.
X
X(4) Create the following directories on your system if they don't already
X    exist.  Be sure to get owners, groups and permissions right!
X
X    /				root	root	drwxr-xr-x	exists
X    /usr			root	users	drwxr-xr-x	exists
X    /usr/lib			root	bin	drwxr-xr-x	exists
X    /usr/lib/cron		cron	bin	drwx------
X    /usr/spool			root	bin	drwxr-xr-x	exists
X    /usr/spool/cron		cron	bin	drwx------
X    /usr/spool/cron/atjobs	cron	bin	drwx------
X    /usr/spool/cron/crontabs	cron	bin	drwx------
X    /etc			root	sys	drwxr-xr-x	exists
X    /etc/daemons		root	sys	drwxr-x---	exists
X    /usr/local			root	users	drwxr-xr-x
X    /usr/local/bin		bin	bin	drwxr-xr-x
X
X(5) Now move the compiled programs into their proper directories.  Link
X    together at, batch, cronjob and crtabj: they're all the same program.
X    Again, make sure you get the owners, groups and permissions right!
X 
X    /etc/daemons/cron		root	bin	-rwx------
X    /usr/local/bin/at		cron	bin	-rws--x--x	\
X    /usr/local/bin/batch	cron	bin	-rws--x--x	 \ link
X    /usr/local/bin/cronjob	cron	bin	-rws--x--x	 /
X    /usr/local/bin/crtabj	cron	bin	-rws--x--x	/
X    /usr/local/bin/crontab	root	bin	-rws--x--x
X
X    Note: neihter the daemon nor the user commands are tied to any
X    particular directory.  You can put them anywhere you like.  Eg. you
X    could put at and batch in /usr/bin or /usr/lbin if that is the custom
X    on your machine.  I put the daemon in /etc/daemons because anything
X    in /etc/daemons is automatically executed on bootup in the UNIX-PC.
X
X(6) Create and edit the allow and deny files.  Again make sure you get
X    the owner, group and permissions right!
X
X    /usr/lib/cron/at.allow	cron	other	-rw-------
X    /usr/lib/cron/at.deny	cron	other	-rw-------
X    /usr/lib/cron/cron.allow	cron	other	-rw-------
X    /usr/lib/cron/cron.deny	cron	other	-rw-------
X
X	IF XX.allow exists, only those users whose names
X		are in it will be able to use this facilty.
X	ELSE IF XX.deny exists, users whose names are in
X		it will not be allowed to use this facility.
X	ELSE only the superuser will be allowed to use it.
X
X    These files, if used, are one name per line.  If you want to let
X    everybody use the at(1) and batch(1), create an empty at.deny file.
X    Similarly, for the cron.allow and cron.deny files.  An interesting
X    note here is that the code is setup to allow two users to clear the
X    log file: root and cron.  However if you refuse permission to cron
X    with the allowfile-denyfile mechanism, then only root will be able
X    to clean the log file.
X
X(7) Reboot to get the daemon running.  You may want to check the file
X    /etc/rc.  On the UNIX-PC, any programs in /etc/daemons are fired-up
X    automatically from /etc/rc at bootup-time.  If your system uses a
X    different scheme, you may have to add a line such as the following:
X
X		/etc/daemons/cron
X
X    to your /etc/rc file.  You might also want to make use of the CATCHUP
X    feature of the daemon by setting the environment variable or calling
X    the daemon with and argument, like this:
X
X		/etc/daemon/cron 86400	# catchup 24 hours
X
X
X                          ***************
X
X----------------------------------------------------------------
X	Caveats for the Cron Facility - D.Lashomb
X----------------------------------------------------------------
X
XThis cron facility was written for the AT&T Unix-PC model 7300.  I believe
Xit should port well to other sysV machines.  How well it will port to BSD
Xmachines, I don't know.
X
XUsers' login shells:  This facility will work with the Bourne shell (/bin/sh)
Xand the Korn shell (/bin/ksh).  I do not know if it will work with csh.  It
Xwill NOT work with login shells that are scripts - the login shell MUST be
Xa binary executable.  It will NOT work unless the shell can accept the
Xoptions "-c" and "-s" the way /bin/sh does.  It will NOT work with some very
Xold shells that choke on '#' comments or blank lines.
X
XMost jobs are automatically marked with an extra newline and a "# job done"
Xline.  This is the reason for the above comment.  The extra newline is also
Xlisted out by "at -lu", for example, even though the "u" option is supposed
Xto only list what the user enterred for the job.
X
XWhen the system is booted and the cron daemon starts-up, it checks the jobs
Xin its spool directory.  AT_JOB, BATCHJ, and CR_JOB jobs are scanned for the
X"# job done" marker.  This helps to insure that these jobs are intact.
XCR_TAB jobs are not scanned - there is no ending marker for them.
XFurthermore, when the daemon finds a CR_TAB job upon startup, it simply
Xchecks that a crontab file EXISTS for that user.  It does NOT re-parse the
Xcrontab file.  This *feature* has an advantage in that it allows the user to
Xenter CR_TAB jobs directly with the crtabj(1) command and have them survive
Xa reboot as long as the user has a crontab file, even a blank one, in place.
XIt has the disadvantage in that spooled CR_TAB jobs have no hard relationship
Xwith the crontab files.
X
XStdout and stderr from users' jobs are mailled to the user using /bin/mail,
Xtherefore /bin/mail must exist on the system.
X
X----------------------------------------------------------------
XNone of the above caveats is insurmountable.  Perhaps some ambitious fellow
Xwill: pepper the code with #ifdef's to make more portable :-)
X
X                          ***************
X
X===                                                                ===
X| The following notes were some of things that I was thinking during |
X| the design of the at(1) facility.  DON'T pay too much attention to |
X| them, many of the details were changed in the final design.        |
X===                                                                ===
X
XThis project is to build an at(1) facility for the unix-pc.
X
X[ wrote all my own code ]
X
XMy design for at(1) consists of basically two programs: a daemon that
Xruns all the time in the backaground, and a user-callable command that
Xaccepts data from the user and passes it to the daemon thru a FIFO.
X
X[ really two fifo.s used ]
X
XIn standard sysV unix, the at(1) facility is co-implemented as part of
Xcron(1M) and both facilities are available to trusted users.  Files are
Xstored in subdirectories using cron's name, like: /usr/lib/cron/FIFO.
XIn the unix-pc, however, smgr(1M) takes the place of cron, and is
Ximplemented more like sysIII unix's cron.  Therefore, it would not make
Xsense to use cron's name on directories that are used only by at(1).
XSo the filenames that I'll use will sort of parallel sysV, but use at's
Xname, like: /usr/lib/at/FIFO.
X
X[ no- used std sysV names ]
X
XSome of the design objectives are:
X
X	performance - don't use too much processor time or tie-up too
X		many of the system's resources.  In a small system like
X		the unix-pc, this is a major consideration.
X
X	security - always a consideration.  The ability to abuse at(1)
X		is well known.  There are basically three ways to break
X		security using at(1).  I won't detail them here, but I
X		will try to guard against all three in my design.
X
X	ease of use - at(1) should be easy for users to use, and easy
X		for the system admin to take care of.  I would very much
X		like to make the user's command line the same as sysV's
X		at(1), but I don't have a manual page from any version
X		of unix to follow.  Therefore, my choice of options and
X		command line arguments may not be *standard*.  I will
X		try to make reasonable choices for them, though.
X
X		[ options and args upwardly compatable with sysV ]
X		[ thanks to John Milton for copy of sysV at(1) man page ]
X
X	multi-user - I'll try to keep in mind that more than one user may
X		be using at(1) at the same time.
X
X	signals - handle them gracefully.  If the user press the SIGINT
X		key, for example, there shouldn't be half-baked/temporary
X		files laying around.
X
XSo here's the basic design:
X
X	The daemon is started up at boot time or whatever, runs in the
X		background and has super-user uid.  It basically reads the
X		FIFO to see if anyone has sent it a message.  If no message
X		is received, it goes to sleep for a little while.  When it
X		wakes up, it checks the time and looks to see if any jobs
X		are scheduled to be done at that time.  If there is nothing
X		to do it just checks the FIFO and goes back to sleep.
X
X	The user calls the at(1) command and gives it the name of a file
X		containing the command he wants done or types the commands
X		in using stdin.  The user also supplies the time at which
X		he wants this stuff done.  At(1) checks to see if this user
X		is allowed to use the facility.  Opens up a temporary file.
X		Puts some environment setup stuff in the temp file (like
X		cd `pwd`) and copies the user's stuff into it.  It then sends
X		a message to the daemon thru the FIFO telling the name of the
X		temp file amoung other things.
X		
X		[ no- only stdin for cmds ]
X		[ no temp file used, writes file in spool directory ]
X
X	When the daemon gets the message from the FIFO, it moves the temp
X		file into the spool directory an gives it a unique name.  The
X		filename, time, uid and other info about the job is put on an
X		in-memory list of jobs; sort of like a symbol table.  This
X		list will probably be orderred on the time that the jobs are
X		supposed to be done so that the daemon can determine which
X		job to run when as quickly as possible.  Otherwise the daemon
X		would have to scan the whole list everytime it wakes up.
X
X		[ job file is already in the spool directory ]
X
X	At some point the daemon will wake up, check its list and find that
X		it is time to run the job.  It will fork off a process, set
X		the uid and gid to the job's owner and call the shell to run
X		it.  I may incorporate the ability to use either sh(1) or
X		ksh(1) and the ability to set a nice value for the job.  The
X		job will be taken off the daemon's list and the file removed.
X
X		[ uses whatever shell defined in /etc/passwd for the user ]
X		[ user can specify nice value ]
X
X	Some details that must be answered: How to connect stdin, stdout and
X		stderr for a job?  If ksh(1) is used, what to do with history?
X		How is the job file removed; by the daemon or by the shell?
X		Can the user delete a job before it runs; if so how does he
X		find it?
X
X		[ stdin is job file, stdout and stderr mailled to user ]
X		[ ksh histfile same as user's. used when read -s or print -s ]
X		[ job rmv'd by unlinking file and/or send rmv msg to daemon ]
X		[ at -l lists jobs, at -r removes them ]
X
X	There is also the consideration of incorporating a batch(1) facility
X		into at(1).  It would be relitively easy to do a simple batch
X		that doesn't monitor system load, just set the maximum nice
X		value and let-her-go.  You could get real fancy, by building
X		a histogram of system load factors and intelegently picking
X		a historically low-load time to run batch jobs; but I think
X		that is going too far.  One simple possiblity is to just count
X		the number of active processes, and if the number is close to
X		the minimum number known to batch, and has stayed close to the
X		minimum for awhile; then run a batch job.  How do you count
X		the number of processes?  Well you could do ps(1) and count
X		the number of lines, but this would create alot of overhead.
X		The other way is to count the kernal's process table directly.
X		I know how to do this.  It's not a easy as it sounds, though.
X		Hmmmm, we'll see, let's concentrate on at(1) first.
X
X		[ batch just runs the job at maximum nice ]
X
X/* --------------------------------------------------------------
X   FIFOs:  daemon ----JNUM----> user
X	   daemon <---FNAM----- user
X
X   Daemon generates unique jobnumbers and sticks them in JNUM fifo.
X   User gets jobnumber from JNUM fifo, uses it as a filename, and
X   puts its information in that file.  When user finishes building
X   the file, it writes the filename(=jobnumber) into FNAM fifo.
X   Daemon reads filename from FNAM fifo, opens the file, reads some
X   info from it and builds its in-memory list.  When the time comes,
X   the daemon runs the job and writes the jobnumber back on the JNUM
X   fifo.  The reasons to do it this way are:  (1) daemon's in-memory
X   list can't overflow because it limits the number of jobnumbers
X   available to the user.  (2) daemon can always build its in-memory
X   list from files in the spool directory at startup time.  (3) the
X   user can build its files directly in the spool directory.  (4) if
X   the daemon finds a file in the spool directory which is not on
X   its list, it means the user has crashed; it can remove the file
X   and make that jobnumber available again.  (5) if the user cancels
X   the job before writing its filename into the FNAM fifo, he writes
X   it back on the JNUM fifo (sneeky!).  (6) the last line in every
X   job file is specially marked.  If everything crashes this line
X   will be missing.  The daemon removes files that don't have this
X   special line at startup.  (7) the daemon opens the job file and
X   unlinks it when the job is run.  The jobnumber is immediately
X   available and the file is deleted automatically when the shell is
X   done, even if something or everything crashes.
X   -------------------------------------------------------------- */
X
X   [ #4 not implemented ]
X   [ caveate: the fifos must be big enough to hold all the job no.s ]
X
Xcron facility  4/89 D.Lashomb
X
XThis project is to add the cron capabilities to the at(1) facility
Xalready implemented.  Some of the key ideas are:
X(1) users are screened thru cron.allow and cron.deny
X(2) only one crontab file for each user
X(3) format of crontab files:
X	# any line beginning with a # is a comment
X	mm hh DD MM ww <action>
X		schedule fields are integers incl ran-ges com,mas
X		action upto \n or first % remainder: %=\n stdin to command
X(4) the daemon scans all crontabs at startup and when new ones are added
X(5) when daemon scans a crontab it generates a job (or jobs) for the next
X    scheduled action.
X(6) when the daemon runs a cronjob it rescans the asscociated crontab, again
X    generating jobs for the next scheduled actions for that user.
X
X[ crontab(1) not implemented yet.  I did cronjob(1) instead. ]
X[ most of the hooks for crontab are in the daemon.  I'll add ]
X[ crontab sometime soon [[ crontab implemented ]]            ]
X
X==================
X
XUser's crontabs are stored in /usr/spool/cron/crontabs with the filename = uid.
XThis is different from sysV, where filenames=lognames.  It also means that you
Xcan't have multiple crontabs for multiple login names with the same uid.  There
Xare some problems in this area with at(1) too.  It could be fixed with great
Xeffort.
X
X[ This is mostly right! My programs go by uid not logname ]
X
XAnother thing is that the crontab(1) command must have read access to the
Xuser's files and yet has to be suid cron to write into the spool dir.  There
Xare a couple of solutions to this.  Could have crontab(1) only a little
Xscript that opens the user's file and pipes it into stdin of the *real* cmd.
XAnother solution would be to have a group called "cron" instead of a login.
X
XHere's how to do it: at(1), batch(1), and crontab(1) are all the same program
Xwhich runs as effective uid = cron, real uid = the user.  Crontab(1) can
Xwrite into the spool directories, but can't read the user's file because its
Xeffective uid is cron.  So it spawns a child that does setuid back to the
Xreal user's uid and pipes the user's file in.
XUser calls crontab(1) and gives the name of his file (or stdin).
XCrontab(1) spawns a "cat" process to pipe the user's file in.  For every line
Xin every user's crontab files, a ct_job is created.  The only reason to keep
Xa copy of the user's crontab file in ...spool/crontabs is so the user can get
Xa copy back with the -l option.  The daemon doesn't use it at all.
X
X[ hooks in the daemon for CR_TAB ]
X[ crontab opens user's file after setuid() back to real uid ]
X[[ note: bug in setuid() won't let you setuid(getuid()) for real uid=0 ]]
X[[       so crontab command must run as SUID root, intead of SUID cron ]]
X
X=================
X
XAnother problem concerns the environment for cron_jobs.  Unfortunately the
XsysV manual page specifically states that a default environment is setup for
Xcron_jobs; incl $HOME (ok), $LOGNAME (ok), $SHELL (so-so) and $PATH (ng).
XWhereas at(1) could just grab the current environment for its jobs, cron will
Xhave to figure-out what to give its jobs.  The sysV manual also specifically
Xstates the .profile will not be executed.  The biggest problem is $PATH.
X$HOME, $LOGNAME and $SHELL can be setup from the passwd file.  If the user's
Xlogin shell is ksh, then $ENV could be executed, if setup.  Now there are
Xreal problems in this area!  In my opinion, a cron_job should be equivelent
Xto at(1), except that it is cyclic instead of one-shot.  Barring that; cron
Xshould be equivelent to logging in and executing the commands by hand, so
Xthat your environment is recreated.  It is MUCH cheaper, however, to do it
Xthe sysV way - for one thing you don't have to save the user's environment
Xanywhere.  But there are a great many programs that depend on various environ
Xvariables being setup.  The best way I think is this:  the crontab(1) command
Xdoes a cd to $HOME first and then saves the environment like at(1). [maybe]
X
X[ uses full user environment as exists when the job is created ]
X[[ doesn't cd to $HOME either, uses current working directory when created ]]
SHAR_EOF
if test   29859 -ne `wc -c <README`
then
	echo "README unpacked with wrong size"
fi
echo "extracting Remove (    882 chars)"
sed 's/^X//' <<'SHAR_EOF' >Remove
X#    Remove for cron(1M) facility  4/89 D.Lashomb
X
XLOCAL=/usr/local
XBIN=/usr/local/bin
XLIB=/usr/lib/cron
XSPOOL=/usr/spool/cron
XDAEMONS=/etc/daemons
XSRC=$HOME/Filecabinet/SRC
XmySRC=$SRC/Cron
XDOCS=$HOME/Filecabinet/DOCS
XmyDOCS=$DOCS/Cron
X
Xecho "killing the cron daemon"
XI=`ps -e | grep 'cron' | cut -c1-6`
Xfor i in $I
Xdo
X	kill -9 $i
Xdone
Xecho "shall I remove the 'cron' login"
Xecho "from your password file y/[n]? \c"
Xcase "`line`" in
X[Yy]*)	mytmp=/tmp/$$
X	grep -v '^cron:' /etc/passwd >$mytmp
X	cp $mytmp /etc/passwd
X	rm $mytmp
X	;;
Xesac
Xecho "removing my programs"
Xrm $DAEMONS/cron $BIN/at $BIN/batch $BIN/cronjob $BIN/crtabj $BIN/crontab
Xecho "removing my directories"
Xrm -r $LIB $SPOOL
Xecho "shall I remove $mySRC y/[n]? \c"
Xcase "`line`" in
X[Yy]*) rm -r $mySRC ;;
Xesac
Xecho "shall I remove $myDOCS y/[n]? \c"
Xcase "`line`" in
X[Yy]*) rm -r $myDOCS ;;
Xesac
Xecho "Remove done"
Xexit 0
SHAR_EOF
if test     882 -ne `wc -c <Remove`
then
	echo "Remove unpacked with wrong size"
fi
echo "extracting Size (      4 chars)"
sed 's/^X//' <<'SHAR_EOF' >Size
X500
SHAR_EOF
if test       4 -ne `wc -c <Size`
then
	echo "Size unpacked with wrong size"
fi
echo "extracting allow.c (   1905 chars)"
sed 's/^X//' <<'SHAR_EOF' >allow.c
X/* Setup and check allow and deny files */
X
X#include <stdio.h>
X#include <pwd.h>
X#include <string.h>
X#include <errno.h>
X#include "cron.h"
X
Xint			getuid();
Xchar			*getenv();
Xint			putenv();
Xchar			*getlogin();
Xstruct passwd		*getpwnam();
X
X#define realuid		getuid()
X
Xvoid			fatal();
X
X
X/*
X * login() - return --> static passwd info or NULL
X */
Xstruct passwd *login()
X	{
X	struct passwd	*userpw;
X	char		*p;
X
X	if((p=getenv("LOGNAME")) != NULL) {
X		if((userpw=getpwnam(p)) == NULL)
X			fatal("get passwd info");
X		if(userpw->pw_uid == realuid)
X			return(userpw);
X		}
X	/*
X	 * LOGNAME env var is either not set or bad
X	 */
X
X#ifdef SET_LOGNAME
X	if(realuid == 0) {
X		if(putenv("LOGNAME=root") != 0)
X			fatal("put LOGNAME in env");
X		if((
X		(userpw=getpwnam("root"))	== NULL) || (
X		userpw->pw_uid			!= 0)
X		)
X			fatal("passwd file bad");
X
X		return(userpw);
X		}
X#endif
X	return((struct passwd *)NULL);
X	}
X
X
X/*
X * allowed() - return 0 if not allowed
X *             return 1 if OK
X */
Xallowed(name,allowfile,denyfile)
X	char		*name;
X	char		*allowfile;
X	char		*denyfile;
X	{
X	FILE		*fp;
X	int		allow;
X	char		line[LINESIZ];
X
X	if(realuid == 0)
X		;
X	else if((fp=fopen(allowfile,"r")) != NULL) {
X		allow = 0;
X		while(fgets(line,LINESIZ,fp) != NULL) {
X			line[strcspn(line,"\n")] = '\0';	/* strip \n */
X			if(strcmp(line,name) == 0) {
X				allow = 1;
X				break;
X				}
X			}
X		if(ferror(fp))
X			fatal("read allow file");
X		if(fclose(fp) != 0)
X			fatal("close allow file");
X		if(!allow) return(0);
X		}
X	else if((fp=fopen(denyfile,"r")) != NULL) {
X		allow = 1;
X		while(fgets(line,LINESIZ,fp) != NULL) {
X			line[strcspn(line,"\n")] = '\0';	/* strip \n */
X			if(strcmp(line,name) == 0) {
X				allow = 0;
X				break;
X				}
X			}
X		if(ferror(fp))
X			fatal("read deny file");
X		if(fclose(fp) != 0)
X			fatal("close deny file");
X		if(!allow) return(0);
X		}
X	else if(errno == ENOENT) return(0);
X	else fatal("open allow,deny file");
X	return(1);
X	}
SHAR_EOF
if test    1905 -ne `wc -c <allow.c`
then
	echo "allow.c unpacked with wrong size"
fi
echo "extracting at.1 (  14170 chars)"
sed 's/^X//' <<'SHAR_EOF' >at.1
X.TH AT 1 LOCAL
X.SH NAME
Xat, batch, cronjob, crtabj \- run commands at a later time
X.SH SYNOPSIS
X.B at
X[-{n|N} nice] time [{next|this}] [date] [+ increment]
X.br
X.B batch
X[-{n|N} nice]
X.br
X.B cronjob
X[-{n|N} nice] mins hrs mdays mons wdays
X.br
X.B crtabj
X[-{n|N} nice] mins hrs mdays mons wdays command
X.br
X{\fBat\fR|\fBbatch\fR|\fBcronjob\fR|\fBcrtabj\fR}
X-r[ae] {all|jobn ...}
X.br
X{\fBat\fR|\fBbatch\fR|\fBcronjob\fR|\fBcrtabj\fR}
X-l[aefu] [jobn ...]
X.br
X{\fBat\fR|\fBbatch\fR|\fBcronjob\fR|\fBcrtabj\fR}
X-c
X.P
X.SH DESCRIPTION
X.IR At (1),
X.IR batch (1),
X.IR cronjob (1),
Xand
X.IR crtabj (1)
Xall allow you to enter commands that will be executed at a later time.
XWith
X.I at
Xyou specify the time and enter the commands you want executed through stdin.
XThese comands will be executed (once) when the time comes.
X.I Batch
Xworks like
X.I at
Xexcept the system picks the time.
XYou enter the commands you want executed through stdin,
Xand they will be executed (once) with minimal load on the system.
X.I Cronjob
Xallows you execute commands on a repetitve basis.
XYou enter the commands you want executed through stdin,
Xand the system executes them according to the schedule you provide.
X.I Crtabj
Xalso works repetitively but only executes a single command.
XAny input thru stdin is passed to the command's stdin when it is executed.
X.P
XThis information is saved by the
X.I "cron facility"
Xand assigned a job number which is reported to the user.
XWhen the time comes, the job will be executed by the shell specified
Xfor the user in the
X.B /etc/passwd
Xfile.
XThe job's
Xstandard output and standard error output are
Xmailed to the user unless they are redirected elsewhere.
XThe shell environment variables, current directory,
Xumask, and ulimit are retained when the commands
Xare executed.
XOpen file descriptors, traps, and priority are lost.
X.P
XUsers are permitted to use
X.I at
Xand
X.I batch
Xif their name appears in the file
X.BI /usr/lib/cron/at.allow .
XIf that file does not exist,
Xthe file
X.B /usr/lib/cron/at.deny
Xis checked to determine if the user
Xshould be denied access to them.
XIf neither file exists, only the superuser is allowed to
Xsubmit a job.
XSimilarly, the use of
X.I cronjob
Xand
X.I crtabj
Xis controlled by the files
X.B /usr/lib/cron/cron.allow
Xand
X.BR /usr/lib/cron/cron.deny .
XThe allow/deny files consist of one user name
Xper line.
XIt should be noted that
X.IR at ,
X.IR batch ,
X.IR cronjob ,
Xand
X.I crtabj
Xcheck the real uid, not the effective uid of the user.
X.P
X.IR At (1),
X.IR batch (1),
X.IR cronjob (1),
Xand
X.IR crtabj (1)
Xreport the job number and scheduled execution time on standard error.
X.P
XThe user can specify the nice value increment
Xto use when the job is executed by using the
X.B -n
Xoption.
XThe superuser can specify the
X.B -N
Xoption, in which case the
X.I nice
Xparameter is interpreted as negative.
X.P
X.ce
X.B at
X.ce
X.B ==========
XThe
X.I time
Xmay be specified as 1, 2, 3 or 4 digits.
XOne and two digit numbers are taken to be hours,
Xthree or four digits
Xto be hours and minutes.
XThe time may alternately be specified as two numbers
Xseparated by a colon, meaning
X.IR hour : minute .
XA suffix
X.B am
Xor
X.B pm
Xmay be appended;
Xotherwise a 24-hour clock time is understood.
XThe suffix
X.B zulu
Xmay be used to indicate GMT.
XA space between the number and the suffix is OK.
XThe special names
X.BR noon ,
X.BR midnight ,
Xand
X.B now
Xare also recognized.
X.P
XOptionally the word
X.B next
Xor
X.B this
Xcan be used in lieu of
X.I time
Xor in addition to it.
XIf used in place of
X.IR time ,
Xthe current clock time is assumed (ie
X.BR now ).
X.P
XAn optional
X.I date
Xmay be specified as either a day of the week,
Xor a month name followed by a day number (and possibly year number).
XA year number must be 4 digits and is separated from the day number
Xby a comma, a space or, a comma and a space.
XTwo special days,
X.B today
Xand
X.B tomorrow
Xare recognized.
XIf no
X.I date
Xis given,
X.B today
Xis assumed if the given
X.I time
Xis greater than the current time and
X.B tomorrow
Xis assumed if it is less.
XIf the given day of the week is less than the current day of the week,
Xnext week is assumed.
XIf the given month is less than the current month (and no year is
Xgiven), next year is assumed.
XPreceeding the
X.I date
Xwith
X.B next
Xor
X.B this
Xwill override these assumptions.
X.P
XThe optional
X.I increment
Xmust be preceeded by a
X.B +
X(plus sign) and
Xis simply
Xa number
Xsuffixed by one of the following:
X.BR minutes ,
X.BR hours ,
X.BR days ,
X.BR weeks ,
X.BR months ,
Xor
X.BR years .
XSpaces between the plus sign, number and suffix are optional.
X.P
XAdditional comments:
XOnly the first three letters of any word are needed.
XUpper or lower case letters are OK.
XThe following words are also recognized:
X.BR nxt ,
X.BR hrs ,
X.BR wks ,
X.BR mos ,
Xand
X.BR yrs .
XIf you use
X.B next
Xor
X.BR this ,
Xyou must specify a
X.IR date .
XYou can't use a year number,
X.BR today ,
Xor
X.B tomorrow
Xwith
X.B next
Xor
X.BR this .
X.B "Next Wed"
Xmeans the Wednesday of next week.
XLikewise
X.B "this Apr 19"
Xmeans April 19th of this year.
X.bp
X.P
XThus valid
X.I at
Xcommands include:
X.P
X.RS 8
X.nf
Xat 0815am Jan 24
Xat 8:15am Jan 24, 1990
Xat now + 1 day
Xat now tomorrow
Xat 5 pm next Friday
Xat 1700 this Fri +1week
X.fi
X.RE
X.P
X.ce
X.B batch
X.ce
X.B ==========
X.I Batch
Xsubmits a batch job to the facility.
XIt is almost equivalent to
X.BR "at now" .
XThe main difference is that the system only starts execution
Xon one batch job at a time.
XAn additional difference is that
X.I batch
Xdefaults to the maximum nice value if the
X.B -n
Xor
X.B -N
Xoption is not used.
X.P
X.ce
X.B cronjob
X.ce
X.B ==========
XA
X.I cronjob
Xschedule consists of 5 fields:
X.P
X.RS 8
X.nf
X\fBmins\fR  - minutes    (0...59)
X\fBhrs\fR   - hours      (0...23)
X\fBmdays\fR - month days (1...31)
X\fBmons\fR  - months     (1...12) or (January...December)
X\fBwdays\fR - week days  (0...6)  or (Sunday...Saturday)
X.fi
X.RE
X.P
XEach of these is a pattern that may be an asterisk
X.RB ( * ),
Xmeaning all valid values;
Xor a list of elements separated by commas
X.RB ( , ).
XAn element is a number, name, or two elements separated by a dash
X.RB ( - ),
Xmeaning an inclusive range.
XOnly the first three letters of any name are needed.
XUpper or lower case letters are OK.
XNote that there are two fields which specify days
X(day of the month and day of the week).
XIf both are specified, both are adhered to; in this way:
X.P
X.RS 8
X.nf
X0 0 1 * 0 = first of every month and every Sunday.
X0 0 1 * * = only the first of every month.
X0 0 * * 0 = only on Sundays.
X0 0 * * * = every day, of course.
X.fi
X.RE
X.P
XYou should note that an asterisk is a special character to the shell,
Xso you should protect it from the shell with quotes.
XYou can enclose the entire schedule in quotes or individual fields,
Xhowever you want.
X.P
XThus valid
X.I cronjob
Xcommands include:
X.P
X.RS 8
X.nf
Xcronjob '30 5 * * Sun'
Xcronjob '5,10,15,20,25,30 * * * *'
Xcronjob 00 7-12,13-17 '* *' mon-FRI
Xcronjob 0 0 1 January \e*
X.fi
X.RE
X.bp
X.P
X.ce
X.B crtabj
X.ce
X.B ==========
X.I Crtabj
Xuses the same scheduling format as
X.IR cronjob .
XIn addition the
X.B command
Xto be executed is stated on the command line.
XI/O redirection can be applied to the
X.B command
Xif it is protected from the shell with quotes.
XLike the scheduling fields, the
X.BR command ,
Xits arguments, and I/O redirection can be separately quoted or
Xthe whole thing enclosed in quotes.
X.P
XValid
X.I crtabj
Xcommand lines include:
X.P
X.RS 8
X.nf
Xcrtabj '30 5 * * Sun echo hello world >/dev/tty0'
Xcrtabj '5,10,15,20,25,30 * * * *' 'who >>online'
Xcrtabj 00 7-17 '* *' 1-5 uudeamon.hr '>/dev/null'
Xcrtabj 0 0 1 January \e* date \e> `tty`
X.fi
X.RE
X.P
XNote:
X.I crtabj
Xis the underlying command for
X.IR crontab (1).
XIt would not usually be called directly by the user.
XIn fact, CR_TAB jobs will not survive a system reboot unless
Xthe user has a
X.B crontab
Xfile in place.
XSee
X.IR crontab (1)
Xfor more information.
X.SH OPTIONS
X.sp
X.ce
X.B scheduling jobs
X.TP 8
X.BI -n " nice"
XSpecifies the nice value increment to apply to the job when
Xit is executed.
X.TP 8
X.BI -N " nice"
XSpecifies a negative nice value increment to apply to the job
Xwhen it is executed.
XThis option can only be used by the superuser.
X.P
X.ce
X.B "removing jobs (-r)"
X.TP 8
X.B -r
XRemoves jobs.
XYou can specify which jobs to remove by either
X.IR jobn ,
Xwhich is the job number given to you previously by the
X.IR at ,
X.IR batch ,
X.IR cronjob ,
Xor
X.I crtabj
Xcommand;
Xor by using the word
X.BR all ,
Xmeaning all the jobs (of the corresponding type) belonging to you.
XYou can only remove your own jobs unless you are the superuser.
X.TP 8
X.B -a
XAny job type.  Without this option;
X.I at
Xonly looks for AT_JOBs,
X.I batch
Xonly looks for BATCHJobs,
X.I cronjob
Xonly looks for CR_JOBs,
Xand
X.I crtabj
Xonly looks for CR_TAB jobs.
X.TP 8
X.B -e
XEverybody.
XSo,
X.B "at -re all"
Xremoves all the AT_JOBs if you are the superuser.
X.bp
X.P
X.ce
X.B "listing jobs (-l)"
X.TP 8
X.B -l
XListing jobs.
XDefaults to one job per line
Xshowing jobnumber, type of job (AT_JOB, BATCHJ, CR_JOB, or CR_TAB),
Xscheduled execution time (next scheduled time for
X.I cronjob
Xand
X.I crtabj
Xjobs),
Xuser's name, user's group, nice value, umask value and ulimit value.
XIf you don't specify any
X.I jobn
Xarguments,
Xlisting will default to all of the
X.RI ( at ,
X.IR batch ,
X.IR cronjob ,
Xor
X.IR crtabj )
Xjobs that belong to you.
X.TP 8
X.B -a
XAny job type.  Without this option;
X.I at
Xonly looks for AT_JOBs,
X.I batch
Xonly looks for BATCHJobs,
X.I cronjob
Xonly looks for CR_JOBs,
Xand
X.I crtabj
Xonly looks for CR_TAB jobs.
X.TP 8
X.B -e
XEverybody.
XAllows you to list other users' jobs.
X.TP 8
X.B -f
XFull listing.  Displays a full multi-line listing of jobs;
Xcomplete with header, environment and user commands.
XOnly your own jobs, unless you are the superuser.
X.TP 8
X.B -u
XUser commands.  This option displays user supplied part of a job
X(ie. that part that was originally enterred through stdin).
XOnly your own jobs, unless you are the superuser.
X.P
X.ce
X.B "clean the log file (-c)"
X.TP 8
X.B -c
XThis option can only be used by the superuser or login cron.
XIt tells the daemon to clean its log file.
X.SH HINTS
XYou should check the scheduled execution time reported to you
Xto make sure that it is what you want.
XYou can press the interrupt key (DEL), to cancel the job
Xwhile you enterring commands, if you do it before you press cntl-D.
X.SH EXAMPLES
XThe
X.IR at ,
X.IR batch ,
Xand
X.I cronjob
Xcommands read from standard input to get the commands to be executed
Xat a later time.
X.IR Sh (1)
Xand
X.IR ksh (1)
Xprovide various ways of specifying standard input.
XWithin your commands, it may be useful to redirect standard output.
XThis sequence can be used at a terminal:
X.sp
X.nf
X.in +1i
Xbatch
Xnroff \fIfilename\fP >\fIoutfile\fP
X<control-d> (hold down control and press d)
X.in -1i
X.sp
X.fi
X.bp
XThis sequence, which demonstrates redirecting standard
Xerror to a pipe, is useful in a shell procedure (the sequence of
Xoutput redirection specifications is significant):
X.sp
X.nf
X.in +1i
Xbatch <<!
Xnroff \fIfilename\fP 2>&1 >\fIoutfile\fP | mail \fIotherlogin\fP
X!
X.in -1i
X.fi
X.sp
XHad you wanted to mail errors to yourself, the redirection and pipe to
X.I mail
Xwould be unnecessary because
X.I batch
Xautomatically mails stdout and stderr to you.
X.sp
X.fi
XTo have a job reschedule itself, or another job, invoke
X.I at
Xfrom within the shell procedure.
XFirst prepare a
X.I shellfile
Xsimilar to the following:
X.sp
X.nf
X.in +1i
Xecho "Time to go home" > /dev/\fImytty\fR
Xat 5 pm tomorrow < \fIshellfile\fR
X.in -1i
X.sp
XAnd then kick it off by typing:
X.sp
X.in +1i
Xat 5pm today < \fIshellfile\fR
X.sp
X.in -1i
X.fi
XAn even better way is to use
X.I cronjob
Xfrom the terminal like this:
X.sp
X.nf
X.in +1i
Xcronjob '00 17 * * Mon-Fri'
Xecho "Time to go home" > /dev/\fImytty\fR
X<control-d>
X.in -1i
X.fi
X.SH NOTES
XThe user must have the
X.B LOGNAME
Xenvironment variable set properly or access will be denied.
XIn the case of the superuser,
X.B LOGNAME=root
Xwill (usually) be put into the environment if need be.
X.P
XThe
X.B TZ
Xenvironment variable, if set in the user's environment,
Xwill (usually) be replaced by the daemon's value when the job is executed.
X.SH CAVEATS
XThe shell which runs the commands saved by
X.IR at ,
X.IR batch ,
Xand
X.I cronjob
Xreads these commands from a file with the shell's stdin
Xconnected to this file.
XIf one of the commands also reads stdin,
Xit could mess up the shell.
XThis problem does not occur with
X.I crtabj
Xwhere the command's stdin is supposed to read it.
X.P
XThe syntax of the command line is probably upwardly compatable with the
Xstandard sysV version of
X.IR at (1),
Xbut I don't guarantee it.
XUnlike the standard sysV version, this version will allow you to do
X.BR "at now" .
X.bp
X.SH FILES
X.nf
X/usr/lib/cron             main cron directory
X/usr/lib/cron/at.allow    list of allowed users \e at
X/usr/lib/cron/at.deny     list of denied users  / batch
X/usr/lib/cron/cron.allow  list of allowed users \e cronjob
X/usr/lib/cron/cron.deny   list of denied users  / crontab
X/usr/spool/cron/atjobs    spool area for jobs
X/usr/spool/cron/crontabs  save area for crontabs
X/usr/local/bin/at         user command
X/usr/local/bin/batch      user command
X/usr/local/bin/cronjob    user command
X/usr/local/bin/crtabj     user command
X/usr/local/bin/crontab    user command
X/etc/daemons/cron         queues and executes jobs
X/usr/lib/cron/log         log of all daemon's actions
X/usr/lib/cron/FNAMES      FIFO from user to daemon
X/usr/lib/cron/JNUMBS      FIFO from daemon to user
X.fi
X.SH SEE ALSO
Xcron(1M), crontab(1), kill(1), ksh(1), mail(1), nice(1), ps(1), sh(1).
X.SH DIAGNOSTICS
XReports various syntax errors and times that are out of range.
XExit value of 0 is returned if all OK, 1 if an error occurs but
Xprocessing continued (like trying to remove another user's job),
Xor 2 if processing can't even get going.
X.SH WARNINGS
XThis facility can only be used by logins that use the standard
XBourne shell,
X.IR sh (1)
Xor the Korn shell,
X.IR ksh (1).
X.SH BUGS
XThe -n or -N nice value increment is not applied to the user's
Xnice value when the job is executed, rather it applies to the
Xdaemon's value.  This is not worth fixing:
Xthe daemon and users usually have the same nice value (20).
X.P
XThe owner of a job is not informed if the job can't be executed
X(eg too old) and was removed my the daemon.
X.SH AUTHOR
XDonald Lashomb  4/89
SHAR_EOF
if test   14170 -ne `wc -c <at.1`
then
	echo "at.1 unpacked with wrong size"
fi



More information about the Comp.sys.att mailing list