Subject: Re: misc/17621: Better system for managing cron jobs (such at Debian /etc/cron.d)
To: None <tibbetts@terc.edu>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
Date: 07/17/2002 16:29:43
[ On Wednesday, July 17, 2002 at 08:40:19 (-0700), tibbetts@terc.edu wrote: ]
> Subject: misc/17621: Better system for managing cron jobs (such at Debian /etc/cron.d)
>
> Currently the only way to add a cronjob to a machine is to extract,
> edit, and reinstall the crontab for a user. This system was designed
> and works well for users managing cronjobs that happen on their
> behalf. But it does not work well for system tasks that must be run
> out of cron.

That's not quite true.  NetBSD's cron supports a BSD-style /etc/crontab
file (where there's an extra user-id field between the time-spec fields
and the command string), as do all versions of Vixie Cron.

Unfortunately the documentation is very sparse about this feature.

Indeed I find having a user-style crontab file for "root" to be a bad
idea -- or indeed for any system-level service run as any role-type
user.  I've migrated my systems to use only /etc/crontab for system
stuff (and end users who are real people (as opposed to system daemons)
can use 'crontab' to manage personal crontabs if they wish (and are
permitted).

> I suggest a better system, similar to the one used by Debian. I
> include part of the Debian documentation below. The basic idea is to
> have a directory full of files that are like crontabs, but where each
> line specifies not just when to run but which user to run as. This
> directory is similar to /etc/rc.d, but for cron. A given package or
> task would put a single file in the directory, describing the the
> cronjobs it needed run. Administrators could edit these files to
> change frequency or user, or to enable or disable jobs. And the
> package system or management tools could also more easily add and
> remove the files.

I think /etc/cron.d would be a bad hack, though in principle it would be
quite easy to add support for it to the code since in essence dealing
with it is exactly the same as dealing with /var/cron/tabs.

It's not that hard for system management assist programs (and package
management programs) to modify /etc/crontab.  For example here's a
snippet of code from my pkgsrc INSTALL script for smail:

	# This won't cause any problem even if smail is not enabled
        #
        if fgrep 'libexec/smail/checkerr' /etc/crontab > /dev/null ; then
                :
        elif crontab -l | fgrep 'libexec/smail/checkerr' > /dev/null 2>&1 ; then
                :
        else
		echo "Adding default cron entry for Smail to /etc/crontab..."
                echo "# do smail mail queue maintenance" >> /etc/crontab
                echo "15	5	*	*	*	root	${PKG_PREFIX}/libexec/smail/checkerr" >> /etc/crontab
        fi

Deleting (or commenting out) the same line from /etc/crontab in a
DEINSTALL script would be relatively easy, though as you say it gets
more complex if you have to use 'crontab -l' and a temporary file.

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>