Automate processes with cron and crontab in Solaris

Home -> UNIX -> Solaris

31314 views

From the computer of: qmchenry (339 recipes)
Created: Oct 11, 2003     Updated: Oct 12, 2003


3 comments:
View all comments

Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

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:

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:

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.

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).

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.




3 Recipe comments: View comments

Automate processes with cron and crontab in Solaris by Anonymous
Re: Automate processes with cron and crontab in Solaris by Anonymous
Re: Automate processes with cron and crontab in Solaris by Anonymous



Related recipes:

  Solaris: fuser to find users or processes making filesystem umount fail
  Power off a Solaris system
  Understanding Solaris runtime control scripts
  Solaris: unmounting a filesystem with umount
  Monitor Solaris system load: understanding vmstat
  Change BootPROM settings from the Solaris command line
  Change Solaris DNS client settings
  Reboot a Solaris system
  Prevent Solaris core files creation with coreadm
  Solaris 10: shutdown or stop a zone

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.