Monday, May 26, 2014

Cron Job In Linux

4:23 PM

Cron is time-based job scheduler. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.

Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system wide crontab file (usually in /etc or a subdirectory of /etc) that only system administrators can edit.


Linux Crontab Format


  *         *             *        *          *                   /path-of-script
(min)   (hour)   (dom)   (mon)  (dow )


Field        Description       Allowed Value

MIN        Minute field         0 to 59
HOUR     Hour field           0 to 23
DOM      Day of Month     1-31
MON      Month field         1-12
DOW      Day Of Week     0-6

1. How to list crontab entries

root@linuxstorage:~#crontab -l

2. How to edit and add crontab entries

root@linuxstorage:~#crontab -e 

3.Schedule a Job for Every Minute Using Cron 

* * * * * .         /path-of-script

4.Schedule a Background Cron Job For Every 10 Minutes

*/10 * * * *     /path-of-script

5.Scheduling a Job For a Specific Time

30 09 10 08 *  /path-0f-script
job will run at Aug month(8 month) , 10 day , 9.30 time(am).

6. Schedule a Job For More Than One Instance

00 09,19 * * *   /path-of-script

00 - 0 minute
09 - 9 am
19 - 7 pm

job will run in both timings 9:00 & 19:00.

7 .Schedule a Job for Specific Range of Time

00 09-19 * * *   /path-of-script
09 - 19 = time from 9 to 19.  9,10,11,12,13,14,15,16,17,18 & 19.

job will run from 9:00 to 19:00 every one hour.

8. Cron for visiting URL

* * * * *    /usr/bin/wget   http://your-website/cron.php 

* * * * *   /usr/bin/curl      http://your-website/cron.php

* * * * *    /usr/bin/wget   -q -o http://your-website/cron.php  

Written by

0 comments :

Post a Comment

 

© 2014 Linux Storages | Updated . All rights resevered. Designed by Templateism