Sunday, 17 April 2016

How to set Cron tasks ?


The cron daemon is a long running process that executes commands at specific dates and times.

Commands for managing cron tab file

crontab
Install filename as your crontab file.

crontab -e
Edit your crontab file.

crontab -l
Show your crontab file.

crontab -r
Remove your crontab file.


Entry in cron tab file

Arguments : 
minute (0 - 59) hour (0 - 23) day of month (1 - 31) month (1 - 12) day of week (0 - 7) [Sunday = 0 or 7] 



Examples of scheduling
Every minute
* * * * *

Every 1 minute
*/1 * * * *

At time 23:00:00 every weekday night
0 23 ? * MON-FRI

In 2003 on the 11th to 26th of each month from January to June every third minute starting from 2 past 1am, 9am and 10pm
2-59/3 1,9,22 11-26 1-6 ? 2003

At time 00:30 Hrs on 1st of Jan, June & Dec
30 0 1 1,6,12 *

At every weekday (Mon-Fri) only in Oct.
0 20 * 10 1-5 ?8.00 PM

At midnight on 1st, 10th & 15th of month
0 0 1,10,15 * *

At each midnight on every day
0 0 * * *

At time 12.05, 12.10 every Monday & on 10th of every month
5,10 0 10 * 1


Example of job entries

Call the servlet every 10 minutes
*/10 * * * * curl http://myserver:8080/myapp/someservlet
equivalent to
0,10,20,30,40,50 * * * * curl http://myserver:8080/myapp/someservlet

Run a Perl script (user program test.pl) every two hours, namely at midnight, 2am, 4am, 6am, 8am, and so on
0 */2 * * * /home/username/test.pl


Setting Cron job on Windows

1. Make a *.bat file while with following content : 
explorer http: //myserver:8080/myapp/someservlet

2. Set a cron job in the Window's control pannel, and set to run this cron job at required time.

Another CRON pattern example
Date/Time (now) : 18-07-2013 11:00 AM
Target date/time for CRON job : After 15 minutes (means, 18-07-2013 11:15 AM)
CRON job pattern : 15 11 18 07 *  [command-to-execute-task]

No comments:

Post a Comment

Note: only a member of this blog may post a comment.