|
Cron Tutorial: Managing cron is Easy!
What is cron?
Actually it is called 'cron daemon'. Cron is an automatic task machine. You will use it on your Unix or Linux operating systems for doing some tasks at specific intervals with out your intervention every time. You set the clock and forget. The cron daemon runs the work for you.
What is cron tab?
'Cron tab(CRON TABle)' is a text file that contains a series of cron functions.
What cron will do for you?
* If you want to send your email cources to your subscribers at 11.30 night, you will set the cron job on your server. And your cron manager sends one email every day at 11.30 until all the emails will be finished. If you want to send them on Sundays, you can schedule it with your cron.
* You can schedule it to delete your website members with expired accounts.
* You can schedule it to recieve an update on your subscribers from your mailing list manager.
* You can check your links on other websites in link exchange programms.
Have your webserver cron enabled?
Have you seen any icon with a name 'Cron Jobs' in your control panel?
Have you seen a text link like 'Cron Manager' or 'Cron jobs'?
If you see one, then you are cron enabled. Ask your host about your cron availability. Some host allows cron with out graphical interface. You have to access it through telnet.
If you are hosted on Virtual hosting domains then your system administrator has to set up your cron tabs for you.
What are the components of cron?
=Field====Value====Description=
minute====00-59====exact minute the cron executes
hour======00-23====hour of the day the cron executes(0 means midnight)
day=======01-31====day of the month the cron executes
month=====01-12====month of the year the cron executes
weekday===00-06====day of the week the cron executes(Sunday=0,Monday=1...)
command===Special==complete sequence of commands to execute
Examples how to set cron:
If you have installed a php script in your piblic_html/www/html directory called members.php and wanted to run this program each night as 11.30 PM as in above example.
You would setup the following crontab line:
30 23 * * * /home/username/www/script/members.php
30--represents the minute of cron work
23--represents the hour of the day
The * represent every day, month, and weekday.
If you want to set the cron job every sunday at midnight 11.30 PM then it would be like:
30 23 * * 0 /home/username/www/script/members.php
0--represents the Sunday.
If you want the cron job to run at 1:00 and 2:00 A.M then you can set it like:
* 1,2 * * * /home/username/www/script/members.php
This runs your cron at 1 and 2 A.M every day, every month and every week.
If you want to run the above task only from Monday to Friday then set it like:
* 1,2 * * 1-5 /home/username/www/script/members.php
Setting up the cron:
Now every host panel is equipped with graphical user interface to set up cron jobs. How easy is that!
Here I am descriding cpanel user interface:
1. Login into your cpanel.
2. Click on 'Cron jobs' icon on your cpanel home page.
3. You will be taken to a page with two buttons - 'Standard' and 'Advanced'.
4. Click on 'Standard' which leads you to a graphical user interface.
5. Select the minutes, hours, day and month.
6. Enter the script file path as absolute path.
7. You have to define the php path before the script path. This can be 'php' or '/usr/bin/php'.
8. See example: I set the cron to run every day night 11.30 and path pointing to a members.php script.
http://www.scripts4webmasters.net/images/cron-cpanel.jpg
Input your email at top right side so you will receive any errors if cron job is not correctly set. Once you'd make sure that cron running properly, you can remove your email and leave the box empty.
TIPS in setting up your cron jobs:
* Ask your host about the procedure if you are not sure of a thing.
* Check your cron once in a while. For example you set your cron to send your ezine at 11.30 PM. Then you subscribe yourself to see it is working or not.
* If you are setting the script path in your schedule, the path SHOULD be from your hosts server root. NOT your domain path. Ex:/home/user/www/script/members.php is correct.
http://www.yourdomain.com/script/members.php is incorrect.
* Script names are case sensitive on Unix. So be careful in entering the script name.
Author Bio:
Radhika Venkata
Home for PHP Autoresponder Software!
http://www.scripts4webmasters.com/ |