[K12OSN] cron & crontab (was Re: Presentation Freezing)

Petre Scheie petre at maltzen.net
Tue Feb 22 14:15:10 UTC 2005

You can, obviously, put jobs in /etc/crontab, but it seems a 
bit...inconsistent, since /etc/crontab is used primarily to call other 
cron scripts in /etc/cron.hourly and so on.  /etc/cron.d/ exists so that 
packages can install their own cron scripts for maintenance; all they 
have to do during installation is drop the script into /etc/cron.d, 
which is easier than modifying a crontab file itself directly.

My colleagues and I generally put backup scripts in root's crontab, 
/var/spool/cron/root, I think partly because if one of us adds a job, 
and later another needs to look at it, the first place we tend to look 
is root's crontab because we know that it was added by us; that is, it 
didn't come as part of the stock OS.  I don't think the Unix police will 
come knocking on your door if you put backup jobs in /etc/crontab, but 
if someone else has to figure out how your system is configured, I think 
they would more likely look at /var/spool/cron/root than /etc/crontab. 
Others may argue otherwise.


Rob Owens wrote:
> Question:
> I've been editing /etc/crontab to do things like
> performing nightly backups and updates.  It works, but
> I guess you are saying it's the wrong way to do it,
> and that I should be using root's "personal" crontab. 
> Could you give an example of what should be in
> /etc/crontab?  I see your example of /etc/cron.d.  My
> system has both /etc/crontab and /etc/cron.d so I
> guess I'm not sure what each of their purpose is.
> -Rob
> --- Michael C Wescott <wescott at sc.rr.com> wrote:
>>cron(8) is a program designed to run other programs
>>periodically. It is
>>controlled by some configuration files called
>>"crontabs" that come in
>>two flavors. One type of crontab file lives as
>>/etc/crontab or as a file
>>in the /etc/cron.d directory. The second type lives
>>in the
>>/var/spool/cron directory and takes the name of it's
>>crontabs of the first kind have the 6th field
>>indicating the user whose
>>privileges with which the command will run. These
>>crontabs should be
>>considered as system files. Don't change them unless
>>you really know
>>what you are doing. The ones in /etc/cron.d are
>>usually specific to some
>>package. I don't see any in a k12ltsp system I've
>>got available but my
>>home system (Debian) shows several all associated
>>with a particular
>>	~ $ ls /etc/cron.d
>>	anacron  logcheck  sendmail  uucp
>>	~ $ 
>>Having a directory with a package-specific crontab
>>makes it easy for a
>>package to install cron entries without trying to
>>edit one or more
>>standard crontabs.
>>These system crontabs can be editted with any text
>>A user (including root) should find his crontab in
>>These crontabs don't use the username in the sixth
>>field since all
>>commands in that file will be run with the user's
>>privileges. These
>>crontabs should be installed, removed and editted
>>using the crontab(1)
>>command. For details on the format see crontab(5),
>>but briefly there are
>>two types of lines (other than empty or comment
>>lines). One sets an
>>enviroment variable and looks like:
>>ENVVAR = some value
>>The other type has at least 6 whitespace separated
>>fields. The first 5
>>determine when the command should be run. The 6th
>>(and following) are
>>treated as a command line and executed by a shell,
>>much as if it had
>>been run with  /bin/sh -c "command line".
>>The rules for exactly when to run the command can be
>>fairly complicated
>>so read the man page crontab(5) more than once.
>>The current version of cron(8) is quite good about
>>"doing the right
>>thing" but it wasn't always so. In olden times (i.e
>>some Unix systems)
>>had some very interesting bugs that popped up when a
>>command was
>>scheduled to be run when daylight savings time
>>On Fri, 2005-02-18 at 13:11, Rob Owens wrote:
>>>No commas in the crontab file (at least not in
>>A comma is a separtor within a time field but not
>>between different
>>fields. Whitespace is used between fields.
>>15,45    9-11,13-16    *     *     1-5    echo
>>"working hours"
>>Will execute the command 'echo "working hours"'
>>every hour at 15 and 45
>>minutes after the hour between 9 and 5 pm (not
>>including a lunch break
>>at noon) on every weekday.
>>>Here is a sample that I pulled from "man crontab".
>> In
>>>my crontab file, the 6th field is usually "root"
>>>the user whose account will run the specified
>>Err ... no, the sixth field only shows up in the
>>special crontabs that
>>you really don't want to mess with.
>>>The ">> $HOME/tmp/out 2>&1" part means to send all
>>>output, errors and otherwise, to a file:
>>Close. The ">> $HOME/tmp/out" part means to append
>>stdout (the normal
>>output of the command) to $HOME/tmp/out. The 2>&1
>>part means to do to
>>stderr (usually error messages) whatever was done to
>>>Brandon Kovach <bkovach at lrhs.greene-r8.k12.mo.us>
>>>This will be my first effort at cron, so please
>>>confirm that this is how 
>>>the cron file should be setup.
>>>0, 23, *, *, 1-5, del /tmp/*.*
>>Lose the commas. Don't you mean "rm" rather than
>>"del"? And *.* will
>>match any file with a dot in it, except those
>>starting with a dot. I
>>think you probably want
>>0   23  *  *  1-5  /bin/rm -f /tmp/*
>>or more likely
>>0   23  *  *  1-5  /bin/rm -r -f /tmp/*
>>The bad part about this kind of blanket removal of
>>files from /tmp is
>>that it is difficult to know when other programs,
>>say other cron jobs,
>>might be using /tmp.
>>>Then I would name the file tmpremove.cron
>>>Then I would do a crontab -l to make sure I had no
>>>files of the same name.
>>>Then I would crontab tmpremove.cron to activate
>>>Is this all correct?
>>Nope. First create a copy of your current crontab;
>>then edit it; then
>>install it as the new version:
>>	[root at drbob root]# crontab -l > xxx.cron
>>	[root at drbob root]# vi xxx.cron
>>	[root at drbob root]# crontab xxx.cron
>>or combine it all into one step:
>>	[root at drbob root]# VISUAL=vi crontab -e
>>	Mike Wescott
>>K12OSN mailing list
>>K12OSN at redhat.com
>>For more info see <http://www.k12os.org>
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Mail - now with 250MB free storage. Learn more.
> http://info.mail.yahoo.com/mail_250
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>

More information about the K12OSN mailing list