Crontab introduction crontab commands are common in Unix and Unix-like operating systems and are used to set periodically executed commands. This command reads commands from the standard input device and stores them in the crontab file for later reading and execution. The word is derived from the Greek chronos (QP? ν ο ?), The original intention is time. Generally, the commands stored in crontab are activated by the Daemon, and crond is often run in the background. check whether a scheduled job needs to be executed every minute. This type of job is generally called cro crontab introduction
Crontab commands are common in Unix and Unix-like operating systems and are used to set periodically executed commands. This command reads commands from the standard input device and stores them in the crontab file for later reading and execution. The word is derived from the Greek chronos (QP? ν ο ?), The original intention is time. Generally, the commands stored in crontab are activated by the Daemon, and crond is often run in the background. check whether a scheduled job needs to be executed every minute. This type of job is generally called cron jobs.
Crontab usage
The crontab format is shown below:
F1 f2 f3 f4 f5 program
F1 indicates the minute, f2 indicates the hour, f3 indicates the day of the month, f4 indicates the month, and f5 indicates the day of the week. Program indicates the path of the program to be executed.
When f1 is *, the program is executed every minute, when f2 is *, the program is executed every hour, and so on.
When f1 is a-B, it indicates that execution is performed from the minute a to the minute B. When f2 is a-B, it indicates that execution is performed from the hour a to the hour B, other analogy
When f1 is */n, the execution is performed every n minutes. if f2 is */n, the execution is performed every n hours.
When f1 is a, B, c ,... A, B, c ,... Execute in minutes. f2 is a, B, c ,... A, B, c... Execute in hours, and so on
Log on to SSH as an administrator, enter the command crontab-e to edit the crontab file, and enter and save the file according to the preceding format.
Crontab example
Run the Command/bin/ls once every 0th minutes of every hour every month:
0 ***/bin/ls
During October 11, December, execute/usr/bin/backup every 20 minutes from to every day:
*/20 6-12*12 */usr/bin/backup
From Monday to Friday, send a letter to alex@domain.name at PM:
0 17 ** 1-5 mail-s "hi" alex@domain.name </tmp/maildata
Every month at midnight 00:20, 02:20, 04:20 .... Execute echo "haha"
20 0-23/2 *** echo "haha"
Every two hours from PM to AM, AM
0 23-7/2, 8 **** date
In hp unix, it is executed every 20 minutes, which indicates: 0, 20, 40 *** instead of */n. Otherwise, a syntax error occurs.
Crontab usage is actually very easy to understand. it is helpful for website and server maintenance, such as regular backup and server optimization.
This article is from "? Pan Songsong? Small blog, please be sure to keep this source http://navyaijm.blog.51cto.com/4647068/816636