| Support Home > VPS v1 > Administration > cron > | Thursday, August 28, 2008 | ||||||||||||||||
cron - Program SchedulerYour Virtual Private Server includes access to the cron daemon which is used to automatically execute scheduled commands. The list of commands you schedule cron to run is stored in a cron table, or crontab. Using your own crontab, you can schedule your Virtual Private Server to run a certain command at a predetermined date and time. Creating a CrontabYour Virtual Private Servers 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 Private Server home directory for your crontab. Each line in your crontab will either be an environment variable setting, a cron table entry, or a comment (beginning with the # symbol).An environment variable setting in a crontab looks like this: NAME = VALUESeveral environment variables are set up automatically by the cron daemon, depending on your Virtual Private Server O/S.
Field Allowed Values ----- -------------- Minute 0-59 Hour 0-23 Day of Month 1-31 Month 1-12, jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec Day of Week 0-7, sun, mon, tue, wed, thu, fri, sat (0 and 7 are "sun") NOTE: In the Day of Week field, you can only use 7 as a value in FreeBSD. Solaris does not recognize the 7 as a valid day.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. The actual command you wish to execute, including any parameters to be passed to it, is the sixth, and final field of a cron table entry. NOTE: Each crontab entry must have a trailing line break in order for the cron table entry to be recognized. Because of this, you may want to hit Enter a few times at the end of your crontab file when you are editing it.Some examples of complete cron table entries are show below, implementing the vnukelog command as an example. # Any output generated by the cron entries below is sent to the e-mail # address assigned to the MAILTO environment variable. MAILTO="webmaster@mycompany.com" # 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 * fri /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 Installing a CrontabAfter 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 crontab command. For example, if you created your crontab file with the name cronjobs in your Virtual Private Server home directory then you would use the following command:% crontab ~/cronjobsThis will register your crontab 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 use this command: % crontab -l DocumentationIssue the following commands to view the cron and crontab man pages.% man cron |
|
| Home | Site Map | Customer Backroom | Copyright © 1997-2008 AlpineWeb Design |