Facebook
Banner
XMPP JavaScript Library READ MORE

What are cron jobs?

Linux, Sachin Puri, 2012-01-19 00:28:22

Cron jobs are tasks or jobs which are scheduled to run repeatedly at specific time like hourly, daily or weekly. We make use of "crontab" command in Linux to setup a cron job.

crontab program can be called with following options:

crontab -e      to edit crontab file

crontab -l      show existing cronjobs

crontab -r      remove crontab file

A crontab file contains cron jobs. each job or task is seperated by a new line. Each entry of task or job consists of six fields and each field is seperated by a space:

minute hour day month weekday command

If we want to send output of a task or job to some specific email address to notify about job, we can put following line at top of the crontab file:

MAILTO=username@domain-name.com

Examples :-

Set cron to run a task every minute

* * * * * /home/script/backup.php

 

Set cron to run a task once in an hour

0 * * * * /home/script/backup.php

 

Set cron to run a task once in a day

0 0 * * * /home/script/backup.php

 

Set cron to run a task on 1st and 15th of every month

0 0 1,15 * * /home/script/backup.php

Set cron to run on every monday

0 0 * * 1 /home/script/backup.php

To specify a range you can use you can use - (minus) sign like 1-5. 

To specify multiple values you can seperate them by , (comma) like 1,5,9

Add Your Comment
   
    Yes! I want to receive all comments by email

No Comments Posted Yet. Be the first one to post comment