Crontab syntax Crontab syntax a Crontab file is defined with five segments: day, date and time, and a command code to be executed on a regular basis.
* * * * * command to be executed - - - - - | | | | | | | | | +-----Day of Week (0-6) (sunday=0) | | | +-------Month (1-12) | | +---------Day of month (1-31) | +-----------Hour (0-23) +-------------min (0-59) |
Environment:
RedHat Linux
JDK1.6
Function Description:
Executes the Java program once every 2 o'clock in the morning.
Operation Steps:
1, first, the Java program packaged into a jar package, the package named Unarchivegzipandinsertintodb2_0_1.jar, note to set the jar package of MANIFEST.MF Main-class class,
Copy the jar package to the/usr/local/directory, and also copy the jar package that the jar is dependent on to the/usr/local/directory, such as Test.jar;
2, create shell script in/usr/local/directory, script name auto.sh, script content is:
#!/bin/bash
cd/usr/local/
#!/bin/sh
CD ' DirName $ '
/usr/local/jdk1.6.0_25/bin/java-xms256m-xmx1024m-cp/usr/local/jdk1.6.0_25/lib/tools.jar:/usr/local/jdk1.6.0_25 /lib/dt.jar:/data/applog/unarchivegzipandinsertintodb2_0.1/unarchivegzipandinsertintodb2/. /lib/activation.jar:/data/applog/unarchivegzipandinsertintodb2_0.1/unarchivegzipandinsertintodb2/. /lib/advancedpersistentlookuplib-1.0.jar:/data/applog/unarchivegzipandinsertintodb2_0.1/ unarchivegzipandinsertintodb2:/data/applog/unarchivegzipandinsertintodb2_0.1/unarchivegzipandinsertintodb2/. /lib/systemroutines.jar:/data/applog/unarchivegzipandinsertintodb2_0.1/unarchivegzipandinsertintodb2/. /lib/test.jar::.:/ Data/applog/unarchivegzipandinsertintodb2_0.1/unarchivegzipandinsertintodb2/unarchivegzipandinsertintodb2_0_1. Jar:test.unarchivegzipandinsertintodb2_0_1.UnArchiveGzipAndInsertIntoDB2--context=default "[Email protected]"
Description
/USR/JAVA/JDK1.6/is the Java installation path
Java command must be added after the-CP parameter, cron do not load the system environment variables, if not add this parameter, the program will not execute normally,
Even though the command line can execute correctly, there are problems with cron calls.
3, use the crontab command, enter the following content:
XX * * * */usr/local/unarchivegzipandinsertintodb2_0_1.sh
Description
The/usr/local/unarchivegzipandinsertintodb2_0_1.sh script is executed at two o ' clock every morning, and the meaning of Crontab's grammatical format can be referred to the relevant manual.
Recently, often encountered on the crontab can not be implemented, the preliminary summary of the following several reasons:
First, the reason for the script: In most cases, we have to believe in science, believe that computers, not ghosts, is the problem of our script, this problem caused crontab can not execute the probability of more than 70%. Since the execution of the program to a certain step resulted in crontab terminating execution, I ran into the wrong database when I migrated the code. Causing the inability to access and died there.
Second, the implementation of environmental issues, when we encounter the first case, the general can be manually executed by the program to kill the problem in the cradle, in general, the master should not make the first mistake. The problem is that when we perform the manual execution successfully and the crontab cannot execute, the author encounters the problem of the execution environment, such as the setup problem of the related path. Solution: Execute source/home/user/.bash_profile at the front of the code
Thirdly, the system time is not correct. This problem is best understood, is also a more common and covert problem, solution: Date-s ********
The four is whether our script has executable permissions. You must ensure that the user executing the script has permission to perform the file change.
Five, the crontab daemon died. This is rarely the case, but it does not rule out that we can use it when we are unable to find other reasons. Solution: Restart the process.
In addition, we introduce you a method of how to view the crontab modification time:
Enter the directory/var/spool/cron/there will be n a user name is a file name, as long as the user who established crontab here will have the user name as the file name, the last modification time of the user's crontab last modified time.
Linux crontab Timer settings (regular Java program execution) (RPM)