Crontab is used to schedule tasks and execute some commands at the specified time.
-L
Show the contents of your crontab file crontabl-l
-I
The crontabl-ri prompt is displayed before you delete the crontab file.
-R
Delete the crontab file crontabl-R from the crontab directory.
-E
Edit the user's crontab file crontabl-e
The time table format is as follows:
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 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, and so on
When F1 is */N, it indicates execution is performed every n minutes. If F2 is */N, it indicates execution is performed every n hours, and so on.
When F1 is a, B, c ,... a, B, C ,... execute in minutes. F2 is a, B, c ,... a, B, c... execution in hours, and so on
/Etc/crontab stores some scheduling programs that are running systematically. The scheduled tasks created using the crontab command are stored here.
/Etc/cron. deny indicates that the crontab command cannot be used.
/Etc/cron. allow indicates the user who can use the crontab command
If two files exist at the same time,/etc/cron. allow takes priority.
If neither of the two files exists, only the Super User can schedule a job.
Cron. Monthly
Cron. daily
Cron. Hourly
Cron. Weekly
01 *** root run-parts/etc/cron. Hourly
02 4 *** root run-parts/etc/cron. daily
22 4 ** 0 root run-parts/etc/cron. Weekly
42 4 1 ** root run-parts/etc/cron. Monthly
We place the script files to be executed every day in the/etc/cron. daily directory, so that the cron daemon starts to execute all the scripts under the directory at every morning.
Each user generates his/her own crontab file. These files are stored in the/var/spool/cron directory.
Example:
During October 11, December, execute/usr/bin/backup every 20 minutes from to every day:
0 6-12/3*12 */usr/bin/backup
[Email protected]:
0 17 ** 1-5 mail-s "hi" [email protected]/dev/null 2> & 1
0 */2 ***/sbin/service httpd restart indicates that Apache is restarted every two hours.
50 7 ***/sbin/service sshd start means to enable the SSH service at every day
50 22 ***/sbin/service sshd stop means to close the SSH service at every day
0 0 ** fsck/home check/home disk on the 1st and 15th of each month
1 ***/home/Bruce/backup: Execute the file/home/Bruce/backup at the first point of every hour.
00 03 ** 1-5 find/home "*. XXX "-mtime + 4-exec RM {}\; every Monday to Friday three o'clock, in the directory/home, find the file name *. xxx file, and delete the file four days ago.
30 6 */10 ** ls indicates that the LS command is executed at on the first, 11th, 21st, and 31st of each month.