Tuesday, September 9, 2008

cron jobs in Linux

The most interesting thing in Linux is running your scripts with a specific period of time.
I have a simple tutorial for those, who want to learn OR had facing problems.

1st of all open terminal (know as shell).
Have to use the following commands for different tasks.
commands:
crontab -l (For listing cron jobs)
crontab -r (For deleting cron jobs)
crontab -e (For editing cron jobs)
By -e you will be able to put new cron jobs in cron file in terminal view, it will open cron in terminal in vi editor.
Now use 'i' to enter to insert mode in cron file in vi editor in terminal. This is for writing in cron file.
When finished writing the lines in cron file,press esc key to end up insert mode.
Then hold SHIFT and hit twice z button to save and end up with cron file.
That's it.
To check mail, just type mail in terminal.
Mail will show you the complete details of cron jobs executed.

Now some sample of cron file lines:
*/2 * * * * /usr/bin/php /var/www/monitoring/cron.php
The above file will executed by cron every 2 minutes interval. File is php, so i have mention php path to execute. and in last i give path to complete file to be executed. Which is cron.php.

No comments:

Post a Comment