Below are the settings you can use to schedule cronjobs in linux. Also it shows the way to schedule a java file in cron job.
//Schedule Every One Hour
0 */1 * * * /usr/java/jdk1.6.0_11/bin/java -cp :/home/CLASSPATH/WEB-INF/lib/ojdbc14.jar:/home/CLASSPATH/WEB-INF/lib/mail.jar:/home/CLASSPATH/WEB-INF/lib/activation.jar:/home/CLASSPATH/WEB-INF/lib/poi-3.5-beta5-20090219.jar:/home/CLASSPATH/WEB-INF/lib/mysql-connector-java-5.1.5-bin.jar:/home/CLASSPATH/WEB-INF/classes/com/connections:/home/CLASSPATH/WEB-INF/classes/com.javafilename 1>/home/CLASSPATH/WEB-INF/classes/com/javafilename.log 2>&1
Note: The logs will be written to javafilename.log file
Scheduling other timings:
* 23 * * * (Daily 11 PM)
45 22 * * * (Daily 10:45 PM)
0 */2 * * * (Every 2 hours)
Linux Crontab Format :
MIN HOUR DOM MON DOW CMD
Cron job are used to schedule commands to be executed periodically. You can setup commands or scripts, which will repeatedly run at a set time.
Cron is one of the most useful tool in Linux or UNIX like operating systems.
The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory
crontab is the command used to install, deinstall or list the tables (cron configuration file)
used to drive the cron daemon in Vixie Cron. Each user can have their own crontab file, and though these are files
in /var/spool/cron/crontabs, they are not intended to be edited directly.
You need to use crontab command for editing or setting up your own cron jobs.
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
An operator allows you to specifying multiple values in a field. There are three operators:
The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
The comma (,) : This operator specifies a list of values, for example: "1,5,10,15,20, 25".
The dash (-) : This operator specifies a range of values, for example: "5-15" days , which is equivalent to typing "5,6,7,8,9,....,13,14,15" using the comma operator.
No comments:
Post a Comment