Friday, September 12, 2008

Cron

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 the 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.


Cron Commands:

crontab filename
Install filename as your crontab file. On many systems, this command is executed simply as crontab filename (i.e., without the -a option).

crontab -e
Edit your crontab file, or create one if it doesn't already exist.

crontab -l
Display your crontab file.

crontab -r
Remove your crontab file.

crontab -v
Display the last time you edited your crontab file. (This option is only available on a few systems.)

How to do it?

    Basically FOUR steps:
  • Create cron.txt
  • Upload
  • Install the txt file as cron file with the command 'crontab cron.txt'
  • Check your cron file
Crontab File
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (1 - 7) (monday = 1)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

Examples :
Cron set For Database BackUp

5 21 * * * mysqldump -u root -p --opt specto | gzip > /backup1/abc/spec
to_`date +%Y%m%d%H%M`.gz

Cron Set for run PHP File ..
* 0,6,12,18 * * * /usr/bin/php -q /var/www/html/abc/xyz/expertblog/blogsadmin/runcron.php > /dev/null

No comments: