Automate Processes with Cron and Crontab in Solaris

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: Solaris  

The cron facility provides a powerful, minute-resolution process scheduler. If a process needs to run repeatedly without human intervention, an entry in the crontab file can accommodate most schedules. There are simple rules for modifying the crontab entries that must be followed.


To edit the crontab file, the crontab program must be used. The actual crontab files should not be edited directly because the contents are cached and changes will not take effect until the crond process is restarted. Using the crontab program to edit the crontabs will update the cache when the file is changed. To edit the current user’s crontab file, use the following:

crontab -e

The -e option tells the program to edit a copy of the user’s crontab file. The EDITOR environment variable is referenced to determine which editor to use (default is ed). To set this environment variable, see recipes for ksh and sh.

The superuser can edit a specific user’s crontab by adding the username at the end of this command. The processes run from a user’s crontab will be run as that user. Be careful with commands in root’s crontab because these will run as root and could cause problems. If shell scripts are run from root’s crontab, make sure their file permissions do not allow modification by anyone but root.

The syntax of crontab is simple. Each line represents a single scheduled task. The first five fields represent timing information and everything following is interpreted as the command to schedule. The timing fields in order are as follows:

minutes – 0-59
hours – 0-23
days of month – 1-31
months of year – 1-12
days of week – 0-6 (Sunday-Saturday)

A variety of options work for each field. An asterisk (*) indicates all possible occurrences for that field. A number sets that single occurrence. Two numbers separated by a – indicates a range of values, and numbers separated by a comma indicate a list of occurrences.

Here are several examples:

15 * * * * logcheck
Runs a command called ‘logcheck’ every 15 minutes of every day.

0,15,30,45 8-17 * * 1-5 dobackup
Runs dobackup every 15 minutes (i.e., 8:00, 8:15, 8:30, and 8:45) during business hours (from 8:00 to 17:00) during business days (Monday-Friday).

 

7 Comments -


  1. Javier said on November 6, 2008

    Esta mal!

    15 * * * * logcheck —>>> esto se ejecuta a los 15 minutos de cada hora

  2. bagheera said on September 2, 2009

    more util */15 * * * *

  3. allruiz said on October 10, 2009

    that’s right!

  4. Gerardo said on January 20, 2010

    */15 * * * * will not work in (at least some) Solaris systems.

    It’s much safer to use 0,15,30,45 * * * * , even though it’s more verbose and less elegant.

  5. Helan said on July 29, 2010

    what will happen if we place user in both corn.deny and corn.allow, with explanation pleaseeeee

  6. Jhallr said on August 11, 2010

    enja pullu ettaka lullu….. :)

  7. Fernando01 said on October 30, 2010

    que mojones son

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -