![]() |
Webmaster
Workshop The Beginner's Guides Section |
Front Page Forums Contact Us Terms of Use How To Guides Resource Center |
![]() |
|
GUIDES
GENERAL
SCRIPTING Beginners Guide to Telnet Basic UNIX Commands CHMOD and setting permissions Guide Basic guide to CRONTAB Basic Guide to Paths |
CRONTAB GUIDE What is crontab ( also referred to as cron and cronjob )? It is a method of automating tasks that are preformed on a regular basis. The main use of this for a webmaster is to run a script at regular intervals which perform a task like refreshing content, creating backups, mailing users during the server's quiet time or some such similar task. Firstly ask your host to setup or grant you permission to use crontab if not supplied with your hosting package. A crontab entry consists of six fields the first five set the frequency of the execution of the sixth field which contains the command to be carried out . The first five fields are as follows
There are also three operators that can be included in the first five fields
Let's get those first five fields understood before moving to the sixth field by trying some examples 20 5 * *
* This would mean that
the command should be run at 20 minutes past * 4 * * * This means the command would run at 4am everyday * 2,10,22 * * * This would run the command at 2am, 10am and 10pm Everyday 20 5 * 1-8 * This
means your command would run at 5 20am daily from 3 0 * * 4 Here your command would run at 3 mins past midnight on a Wednesday The sixth field containing the command There are many commands that may be used in this field but here I will only outline the running of a cgi script which is the most common usage by the webmaster. Firstly if we wished to run a script called bulkmail.cgi we would enter the full path to the script. NOTE this must start with a / so this field could look something like /usr/local/apache/www/cgi-bin/bulkmail.cgi or to run listit.pl it would be /usr/local/apache/www/cgi-bin/listit.pl if this field had some output to write a webpage for you for example and it was writing it to output.html in your news directory (http://yourdomain.com/news/output.html ) your command would look something like this /usr/local/apache/www/cgi-bin/listit.pl>/usr/local/apache/www/htdocs/news/output.html Note the > operator meaning output to.. Now if you understand all the above about the 6 fields and what they do we can move onto the actual crontab command Firstly let us create a crontab file to run our bulkmail
script called bulkmail.cgi at 4 am every Wednesday morning .The reason for
doing this may be that you wish to preform this mailing task at a quiet
time for the server. The first step is to open your text editor. Firstly switch OFF word wrap if it has this feature. Next type in the commands which could look like this using the info above * 4 * * 3
/usr/local/apache/www/cgi-bin/bulkmail.cgi Now press return again so you have a blank line at the
bottom. Now save the file as a text file something like mycron.txt and then you would upload it to your server placing it in your top level directory (the directory you are in when you log on to your server.) Now telnet into your server and at the command prompt type crontab -l (note lowercase L ) (this command will list the crontab file) if the cron has been setup for you you should get a file open up. If this happens you are ready to load in your file to do this type at the command prompt crontab mycron.txt And by the magic of the computer age your file will be transferred into the cron file. Check this out by typing crontab -l again There are two other switches for crontab command they are crontab -e ( this opens the file in the server default editor normally VI ) crontab -r (this will remove (delete) the crontab file ) So create your file containing the list of commands save as a text file upload it to your server. Telnet in and type crontab filename.txt to update your cron job DO NOT FORGET THAT BLANK LINE AT THE END OF THE FILE !! |
This
site design and content is © Copyright 2000-2005 by |