SUMMARY: Notifying cron of changes to crontab files

From: Jeff Putsch (
Date: Fri Mar 12 1999 - 06:48:32 CST


Thanks for all the help. From the responses, most of which boiled down to set
the EDITOR environment variable to your favorite editor and use crontab, it is
clear that I wasn't specific enough in my initial question. Some said send
cron a HUP -- that doesn't work for Solaris 2.x, at least where x=5 or x=6.

I'm attaching my original query at the end of this message. Two responses,
were more helpful:

Jay Lessert <> suggested using:

> Something like:
> # crontab -l joebob | hack_cron_script | su joebob -c 'crontab'

Mark Ashley <> was most helpful:

> Yes, but you need to write code to open the /etc/cron.d/FIFO and send
> a message to cron to add the file for the user. crontab(1) uses a call
> called sendmsg(ADD,login,login,CRON) to do it, this sends a struct of
> { "a", "foo", "foo", "c" }; to the fifo via simply write(2) call.
> "foo" of course is the login name.

The basic problem is I'm using a program called cfengine to keep crontabs for
users like root (and possibly regular users) under control. Cfengine will edit
the crontab files for me, but cron doesn't notice when it does so I need to
notify cron. Cfengine allows me to detect if it actually modified the file and
take action based on that. Therefore I need a way to notify cron without using

The solution I end up with will be one of the following:

  1 have cfengine update the crontab, if it changed it, then have cfengine run
     crontab -l joeuser | su joeuser -c crontab

     so the sequence in a cfengine script goes like this:

        edit user's crontab if and only if it needs to be changed
        was it editited?
          if yes set flag
        later in script
          is flag set?
             if yes run "crontab -l user | su user -c crontab"

  2 write the c program to notify cron via the FIFO.

Unless I can find the exact structure definition for the message to cron, I'll
have to stick with 1.

For those who don't yet know what cfengine is, here's a brief description from
the docs:

  Cfengine is a tool for setting up and maintaining BSD ans System-5-like
  operating systems optionally attached to a TCP/IP network. You can think of
   cfengine as a very high level language---much higher level than Perl
  or shell: a single statement can result in many hundreds of operations
  being performed on multiple hosts. Cfengine is good at performing a lot
  of common system administration tasks, and allows you to build on its
  strengths with your own scripts. You can also use it as a netwide
  front-end for cron.

  The main purpose of cfengine is to allow you to create a single, central
  system configuration which will define how every host on your network
  should be configured in an intuitive way. An interpreter runs on every
  host on your network and parses the master file (or file-set); the
  configuration of each host is checked against this file and then, if you
  request it, any deviations from the defined configuration are fixed
  automatically. You do not have to mention every host specifically by
  name in order to configure them : instead you can refer to the
  properties which distinguish hosts from one another. Cfengine uses a
  flexible system of ``classes'' which helps you to single out a specific
  group of hosts with a single statement.

I highly recommend cfengine. For things like these crontab edits a single line
like this:

  AppendIfNoSuchLine "0,15,30,45 * * * * $(cfbin)/cfwrap $(cfbin)/run-cfengine"

will edit the crontab file and add the line ONLY if it is not there. Much
easier than a full script to do this. Espically when then number of checks per
file grows beyond one or two and the number of files grows beyond one or two.

Thanks for the help.


Original query: said:
> I am running Solaris 2.5, 2.5.1 and 2.6. I would like to be able to
> edit crontab files without using the crontab command. The problem is
> cron doesn't notice and needs to be restarted in this case.

> Is there a way to tell cron that a crontab file for a particular user
> has changed without using the crontab command to edit the file?

Jeff Putsch | Internet:
Unitrode |
7 Continental Blvd. | Fax : (US) 603-429-8564
Merrimack, NH 03054 USA | Voice : (US) 603-429-8626 (daytime)

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:13:16 CDT