Hamilton LaboratoriesHamilton C shell 2012User guideExternal utilities

cron

Oregon Coast

cron
Previous | Next

        Run Commands at Specified Times

Usage:  cron [-asLwW!h-] [-o<opt>] [-d <dir>]
                [ crontab1 crontab2 ... ] |
            -install  [-N <name>] [-D <dispname>]
                [-u <user>] [-p <password>]
                [-H <directory] [-MI] <arguments> |
            -start    [-N <name>] [-D <dispname>] <arguments> |
            -stop     [-N <name>] [-D <dispname>] |
            -pause    [-N <name>] [-D <dispname>] |
            -continue [-N <name>] [-D <dispname>] |
            -delete   [-N <name>] [-D <dispname>] |
            -status   [-N <name>] [-D <dispname>]

   cron executes commands at times according to the crontab
   (.crt) files specifed.  If any path specified is a directory,
   cron will run any crontab files in that directory or any
   subdirectory.  If no files are specified, cron will read
   the crontab from stdin.

   Each file is expected to contain a list of activities to be
   run at certain times, specified one per line.  There are six
   fields per line, separated by white space.  The first five
   specify:

      minute             (0-59)
      hour               (0-23)
      day of the month   (1-31)
      month of the year  (1-12)
      day of the week    (0-6, 0 is Sunday)

   Each of these fields may be an asterisk (meaning all legal
   values) or a comma-separated list of elements, where each
   element is either a single number or a range, given as two
   numbers separated by a minus.  If either end of a range is
   omitted, it defaults to the highest/lowest legal value, as
   appropriate.  If the days are specified in both day of the
   month and day of the week fields, the union of those fields
   is used; to specify the days by only one field, the other
   should be an asterisk.  For example, 0 0 1 * 1 means run the
   command at midnight on the first of every month and also
   on every Monday.

   The sixth field of each line is a command that is to be
   executed by the shell at the specified times.  Any percent
   characters in this field (unless escaped by the escape
   character) are translated to carriage return/newline
   combinations.  Only the first line (up to the first % or
   end of line) is passed as a command; the other lines are
   written to the shell as stdin.  If no input lines are
   given, the shell will inherit stdin opened to the nul
   device.

   Blank lines and any lines beginning with # will be considered
   as comments.
 
   If the crontab was read from a file, the shell will inherit
   stdout and stderr handles for writing (appending, if the file
   already exists) to a file created by replacing the .crt
   extension on the crontab file with .nnn, where nnn is the
   linenumber in the .crt file.  (If the crontab was read from
   stdin, then the shell will inherit the stdout and stderr
   that cron inherited when it started.)

   If a syntax or other error is encountered in a crontab, that
   line, but not the rest of the file will be ignored.  The
   rationale is that cron should continue running even if it
   encounters problems; it should not be necessary to restart
   it just because one entry in one crontab contained an error.

   By default, if the crontab is read from a file, commands
   will be run asynchronously, meaning that all entries that
   are ready to run at any given time will be quickly spawned,
   one right after another, without waiting for each to complete
   before the next is spawned.  If the crontab is read from
   stdin, the default will be synchronous execution, meaning
   each must complete before the next starts; that's so any
   output from one won't be jumbled with that of another.  These
   defaults can be overridden with command-line options.

   Once it's started, cron will make an initial scan of the
   crontab files or directories.  Once every minute after that
   it will look for any changes by comparing timestamps on the
   files.


Running Cron as a Service:

   Under Windows NT, there are two ways to run cron.  The
   simplest is as an ordinary process.  But cron can also be
   run as a service, which means it can run even under a
   different ID than the person currently logged in or even
   when no one is logged in.  When run as a service, cron can
   be set up to start up automatically when Windows NT is booted
   or for manual startup using the Services applet in the
   Control Panel.  Finally, as service, cron can be either
   interactive, meaning it and its children get access to the
   console, or non-interactive, meaning it and its children
   will run invisibly, with no display output and no means for
   input through the keyboard or mouse.  Any error messages
   will be appended to a cron.log file in the home directory
   since messages written to the screen would be lost.

   The choice of running cron as either an interactive or non-
   interactive service is this:  if you run it interactively,
   then there may be a security hole since windows will appear
   and your users may be able to interact with the applications
   cron invokes in ways you didn't intend.  Also, the user
   might be annoyed to see windows popping up and going
   away for all those activities scheduled with cron.

   On the other hand, if you run cron non-interactively, then 
   you may not be able to use it to schedule everything you
   need.  For example, if you start notepad from a non-
   interactive copy of cron, notepad will hang because it
   simply can't run properly without access to the console.
   Also, you won't be able to kill the notepad process without
   rebooting due to the way the security mechanism works.

   An alternative to deciding between these differing ways of
   running cron is to run several copies instead.  Each can be
   set up with its own startup and interactive/non-interactive
   characteristics.  But each copy must have a unique service
   and display name.


Service Options:

   -install   Install cron as a service.   The following
              options may be specified with -install:

              -u <user>      Run cron under the specified user
                             name.  The user name should be
                             in the form DomainName\Username or,
                             if the account is in the current
                             domain, as .\Username.  The default
                             is to run under the LocalSystem ID.

                             To be able to start a service under
                             a user ID, that user must have the
                             right to log on as a service.  To
                             grant that right, use the User
                             Manager.  Pull down Policies, select
                             User Rights and in the popup, check
                             Show Advanced User Rights.  You can
                             then select "Log on as a service"
                             and grant that right to selected
                             groups or users.

              -p <password>  Login password for the specified
                             user name.
              -H <directory> Home directory that the cron service
                             should start up in.  Default is the
                             current directory at the time the
                             install was done.
              -M             Manual startup.  Default is
                             to startup automatically when
                             Windows NT is booted.
              -I             Interactive.  Default is non-
                             interactive.  A service can not be
                             installed as interactive if the
                             -u option is specified.
              <arguments>    Any run-time arguments to be passed
                             to cron when it starts.  Note that
                             any options being set up for the
                             service MUST follow any -install
                             options.  The first option that's
                             not an -install option is assumed to
                             be a run-time option.  No syntax or
                             other checks are made during
                             installation that the run-time
                             arguments are sensible.  If no
                             arguments are given with either
                             -install or -start, cron will look
                             for crontab (.crt) files in the
                             home directory.

   -start <arguments>
              Start the previously installed cron service,
              passing it whatever arguments may be desired.
              If the -install operation also specified an
              argument list, this argument list will override
              it.
   -stop      Stop the cron service.
   -pause     Pause the cron service.
   -continue  Allow cron to continue execution after having
              been paused.
   -delete    Delete (uninstall) the cron service.
   -status    Report the status of the cron service.

   All the service options above accept the following additional
   options for specifying the name of the service:

              -N <name>     Service name for naming the entry
                            in the Registry.
              -D <dispname> Display name for use in the Services
                            applet.

   Under NT, each service has two names:  one is the service
   name, which is the name under which all the information
   about that service is stored in the registry.  The second
   is the display name, which is the more human-readable name
   shown in the Services applet in the Control Panel.  By
   default, the service name for cron is "Hamilton_Cron"
   and the display name is "Hamilton Cron Service".

   When installing a service, both the service name and the
   display name must be unique; that is, there can't be any
   other services already installed with that service name
   or with that display name.  Once installed, either name
   may be used to refer to the service.


General Options:

   -a         Asynchronous execution.  Don't wait for one
              command to complete before spawning the next,
              even if the crontab was read from stdin.
   -s         Synchronous execution.   Always wait for one
              command to complete before spawning the next,
              even if the crontab was read from a file.
   -L         Logging.  As each command is spawned, timestamp
              and log it to stdout and to the output file if
              that's not the same as stdout.
   -w         Wait until the next whole minute.  If cron wasn't
              started near a whole minute (i.e., zero to three
              seconds past a whole minute mark), wait until the
              next whole minute before beginning to schedule cron
              events.
   -o<opt>    Remainder of word contains options to be passed to
              the C shell with any commands.  E.g., -oF means
              C shell should do fast startup when running
              commands.
   -d <dir>   Output files should be created in the specified
              directory, not the directory where the .crt files
              were found.
   -!         Install a interrupt handler to shield cron and its
              children from Ctrl-C and Ctrl-Break interrupts.
              (Remember to type this option at the end of the
              list so the space afterward will prevent it from
              being confused as a history reference.)
   -W         Open a new console window rather than using the
              current one.  Only meaningful for cron run as an
              ordinary process, but useful if the -! option is
              specified.
   -h         Help.  (This screen.)
   --         End of options.

Previous | Next