Blue Reef Technical Support Learn about the Blue Reef Virtual Server Reseller ProgramBlue Reef Virtual Server SupportAbout Blue Reef Consulting, Inc.

Blue Reef Virtual ServersBlue Reef Ecommerce ResourcesSearch the Blue Reef Virtual Server Site
Return to Blue Reef Virtual Servers Home Page
Order virtual servers, software, computers, and more!
Return to Blue Reef Main Home Page
Site Map
Support Solutions to help you do business with your Virtual Server.

Blue Reef Virtual Server Home Page
Blue Reef Virtual Server Support
Virtual Server Addons
Administration Utilities
Using Cron to schedule events
Cron Overview
Managing cron with Crontab
Clearing log files with Cron
Request help using our Problem Tracking System
Order a Blue Reef Virtual Server now!

How the Crontab Works

Creating a crontab
Your Virtual Server crontab can be stored in any file you choose. For example, you may wish to create or upload a file called cronjobs in your Virtual Server home directory for your cron table. Each line in your crontab will either be an environment variable setting, a cron table entry, or a comment (beginning with the "#" character).

An environment setting is of the form,


Several environment variables are set up automatically by the cron daemon. These include SHELL, LOGNAME, USER, and HOME. In addition to these settings, cron will look at a special environment variable, MAILTO. Any output generated by your cron jobs will be sent to the address specified by MAILTO (if it is not specified it will be sent to the owner of the crontab). If MAILTO is defined as an empty string (MAILTO=""), no mail will be sent.

Cron table entry fields
There are six fields in a crontab entry. The first five fields pertain to the time in which the event will be scheduled. The sixth field pertains to the actual command you wish to execute.

The format of the cron table entry includes five (5) time fields followed by a command. Commands are executed when the time specified by the date fields matches the server's current time. The five time fields are as follows:

Field Allowed Values
minute         0-59
hour         0-23
day of month         0-31
month         1-12 (or names, see below)
day of week         0-7 (0 or 7 is Sun, or use names)

A field may be an asterisk (*), which indicates all values in the range are acceptable. Ranges of numbers are allowed, e.g. "2-5" or "8-11", and lists of numbers are allowed, e.g. "1,3,5" or "1,3,8-11". Step values can be represented as a sequence, e.g. "0-59/15", "1-31/3", or "*/2".

Months, days, and weeks can be indicated as either names or numbers. When using names, use the first three letters (case-insensitive) of the particular month or day. Numbers must be used when indicating a range or list, however.

NOTE: Each cron table entry must have a trailing line feed (i.e. there must be a blank line at the bottom of the cron file) in order for the command to be executed.

Installing a Crontab
After you have defined the cron table entries in your cronjobs file, you will need to register your crontab with the system. This can be done by running the command "crontab". For example, if you created your crontab file and named it "cronjobs" and stored it in your home directory, then Telnet or SSH to your Virtual Server and type the following command:

    % crontab cronjobs

This will register your cron table file with the cron system daemon. If you ever need to review the current cron entries you have registered with the cron system daemon, you need simply type:
    % crontab -l
Some examples of complete cron entries are show below, implementing the vnukelog command as an example:
    #set the environment variable MAILTO to "". #so that any output generated by the cron entries will be sent to this #address.

    # Execute the "vnukelog" command at 1:15 (15 1) AM every day.
    15 1 * * * /usr/local/bin/vnukelog

    # Execute the "vnukelog" command at 11:40 PM (40 23) on the
    # first day (1) of each month.
    40 23 1 * * /usr/local/bin/vnukelog

    # Execute the "vnukelog" command every 10 minutes for for the first
    # half-hour (0-30/10) of the 9:00 AM and 5:00 PM hours (9,17) on
    # Monday-Friday (1-5).
    0-30/10 9,17 * * 1-5 /usr/local/bin/vnukelog

    # Execute the "vnukelog" command at 4:00 AM, 8:00 AM,
    #12:00 noon, 4:00 PM, and 8:00 PM (0 */4) on each
    # Sunday (sun) every January (jan).
    0 */4 * jan sun /usr/local/bin/vnukelog

    # Execute the "vnukelog" command at 4:30 AM (30 4) on the first,
    # fifteenth (1,15), and each Friday (fri) of every month.
    30 4 1,15 * /usr/local/bin/vnukelog

    # Execute the "vnukelog" command at 12:00 midnight (0 0) on
    # August 19 (8) (aug).
    0 0 19 8 * /usr/local/bin/vnukelog
    0 0 19 aug * /usr/local/bin/vnukelog
Example Crontab File

#use /bin/sh to run commands, no matter what /etc/passwd says
# mail any output to `paul', no matter whose crontab this is
#run 'daily.job' five minutes after midnight, every day; #then output the results into a temp file 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
#run at 2:15pm on the first of every month -- output mailed to Paul 15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays to annoy Joe 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% 23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" 5 4 * * sun echo "run at 5 after 4 every sunday"
The following paragraphs explain the format of your crontab file and is adapted from the manual page on crontab (section 5). If you would like to review the man page, you may do so by connecting to your Virtual Server and typing:
    % man cron
    % man crontab
    % man 5 crontab

Rotating Server Llogs with Cron

Virtual Server Basics

Remote Administration

Administration Utilities

Configuring your Web Server

Advanced Server Topics

Configuring Virtual Subhosts

Recommended Server Books


Apache Server For Dummies Apache Server For Dummies

Unix : Visual Quickstart Guide
Visual Quickstart

UNIX Power Tools
UNIX Power Tools
$47.96 logo
Search for :
Enter keywords...