Last Updated: January 21, 2000
| Automatic Event Scheduler |
Your individual crontab can be stored in any file you choose. For example, you
may wish to create a file "cronjobs" in your home directory for your
cron table. 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 crontab" or "man -s 5
crontab". For your convenience, we have provided you an on-line
crontab man page for your review.
Each line in your crontab will either be an environment setting or a cron table entry. Lines that begin with "#" are considered comments and are ignored. An environment setting is of the form,
NAME=VALUE
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 by empty (MAILTO=""), no mail will be sent.
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 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, i.e. "2-5" or "8-11", and lists of numbers are allowed, i.e. "1,3,5" or "1,3,8-11". Step values can be represented as a sequence, i.e. "0-59/15", "1-31/3", or "*/2".
Names can be used for the "month" and "day of week" fields. Use the first three letters (case-insensitive) of the particular month or day. Ranges or lists of names are not allowed.
The actual command you wish to execute is the sixth field of a cron table entry. Some examples of complete cron entries are show below:
MAILTO="someone@somewhere.com" Explanation: sets the environment variable MAILTO to "someone@somewhere.com". Any output generated by the cron entries will be sent to this address.
|
| 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. |
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".
Cron Tutorial: Clearing Your Log Files
Your Virtual Server includes a complete set of configuration files and log
files (when can be in Separate or Combined format) for your Virtual Web
Service. Your web server logs are appended to every time someone visits your
site. Over time these logs can grow to be very large and can consume all your
available disk space if not managed correctly².
You can easily define a simple cron table entry in your cronjobs file to nuke your log files. The instructions included below guide you through this process step by step.
MAILTO="USER@YOUR-DOMAIN.NAME"
0 1 1 1-12/3 * /usr/local/bin/vnukelog
This will run the command "/usr/local/bin/vnukelog" (which clears all of your log files) at 1 AM on the first day of the first month of every quarter, or January, April, July, and October (1-12/3). Obviously, you will need to substitute a valid e-mail address in the place of "USER@YOUR-DOMAIN.NAME".
If you have created this file on your local computer, FTP the file up to your Virtual Server and store it in your home directory under the name "cronjobs" (you can actually use any name you would like).
crontab cronjobs
Or if you used a name other than "cronjobs", substitute the name you selected for the occurrence of "cronjobs" above.
crontab -l" or remove all of your
registered cron table entries by typing "% crontab -r".
NOTES
¹ - a daemon is a server process initiated at boot time that waits in the background until its service is required.
² - it is possible to turn the logging capability of your web server off.
Copyright © 1996-2000, Last Modified: 21 January 2000A Little Technology Shoppe, LLC (ALTS.NET)®. All rights reserved. All brand names and product names used on these web pages are trademarks, or trade names of their respective holders.