You are on page 1of 2

CRONJOBS and HOW TO USE

The cron daemon is a long running process that executes commands at specific dates and times. To schedule one-time only tasks with cron, use at or batch. For commands that need to be executed repeatedly (e.g. hourly, daily or weekly), use crontab, which has the following options: crontab filename crontab -e crontab -l crontab -r Install filename as your crontab file. Edit your crontab file. Show your crontab file. Remove your crontab file.

MAILTO=user@domain.com Emails the output to the specified address. The crontab command creates a crontab file containing commands and how often cron should execute them. Each entry in a crontab file consists of six fields, specified in the following order: minute(s) hour(s) day(s) month(s) weekday(s) command(s) The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to be executed. The following table briefly describes each of the fields: Field minute hour day month weekday Value 0-59 0-23 1-31 1-12 0-6 Description The exact minute that the command sequence executes. The hour of the day that the command sequence executes. The day of the month that the command sequence executes. The month of the year that the command sequence executes. The day of the week that the command sequence executes. Sunday=0, Monday

command Special The complete command sequence variable that is to be executed.

Each of the patterns from the first five fields may either be an asterisk (*) (meaning all legal values) or a list of elements separated by commas. An element is either a number or two numbers separated by a minus sign (meaning an inclusive range). Note that the specification of days may be made by two fields (day of the month and day of the week). If both are specified as a list of elements, both are followed. For example: MAILTO=user@domain.com 0 0 1,15 * 1 /big/dom/xdomain/cgi-bin/scriptname.cgi The cron daemon would run the program scriptname.cgi in the cgi-bin directory on the first and fifteenth of each month, as well as on every Monday. To specify days by only one field, the other field should be set to *. For example:

MAILTO=user@domain.com 0 0 * * 1 /big/dom/xdomain/cgi-bin/scriptname.cgi The program would then only run on Mondays. If a cron job specified in your crontab entry produces any error messages when it runs, they will be reported to you via email. You may create crontab files in notepad (being sure to upload them in ASCII) or you may create them from the command line (via SSH) by simply typing: Try It! Now that you have read an overview of cron, test your skills by following the steps below. Once completed, you should have a cron file of your own! Step 1: Create a simple text file using Notepad or any simple text editor that contains the following text: MAILTO=yourusername@yourdomain.com [Enter] 58 23 * * * /big/dom/xdomain/cgi-bin/yourscript.pl [Enter] Step 2: Name the text file (example: cronfile.txt). The cronfile name may be replaced with any name you choose. For instance, if you are running a cron to trigger an email reminder script, it could be called reminder.txt. Many choose to simply call it cronfile.txt. Step 3: Upload the file in ASCII. Any standard FTP client or your account's CNC upload feature will work for this. The file must be uploaded in ASCII mode and it is recommended that it be placed in your /big/dom/xdomain/ directory. It may be placed anywhere in your account but to prevent browser access (security risks) it is strongly recommended to place it above your /www directory. Step 4: Connect to your account via SSH and issue the following command: crontab /big/dom/xdomain/cronfile.txt The above tells the server's crontab where the file is located and that you wish to make it active. Make sure the path to the file is the actual path to where the file was placed. If successful, you will be returned to the command bash line. If not, an error will be displayed.

You might also like