How to Use the crontab command in Linux: crond resident command for Task Scheduling
Crond is a Linux Command Used to regularly execute programs. After the operating system is installed, the task scheduling command is started by default. The crond command periodically checks whether there is any job to be executed every minute. If there is any job to be executed, the job is automatically executed. Linux task scheduling mainly includes the following two types:
1. work performed by the system: work to be performed periodically by the system, such as backing up system data and clearing Cache
2. Personal Work: The work that a user regularly performs, such as checking whether there are new emails on the email server every 10 minutes. This work can be set by each user.
Crontab is a scheduled task trigger in Unix systems. Its user permissions are recorded in the following two files:
File
Description
/Etc/cron. deny
Users listed in this file cannot use the crontab command.
/Etc/cron. allow
Users listed in this file can use the crontab command
/Var/spool/cron/
Is the crontab file of all users
/Var/spool/cron/crontabs
/Var/spool/cron/crontabs
The crontab command is in the following format:Crontab-L |-r |-E |-I [username]The parameter meanings are shown in table 1:
Parameter Name
Description
Example
-L
Displays the contents of your crontab file.
Crontabl-l
-I
Prompt before deleting the crontab file
Crontabl-ri
-R
Delete a user's crontab file from the crontab directory
Crontabl-R
-E
Edit the user's crontab file
Crontabl-e
The crontab file created by the user is saved in/var/spool/cron, and its file name is consistent with the user name.
The format is divided into six segments. The first five segments are time sets, and the sixth segment is the command segment to be executed,
The format is as follows :*****
The meanings of the time period are shown in table 2:
Segment
Description
Value Range
Section 1
Minutes
0-59
Section 2
Represents the hour
0-23
Section 3
Represents a date
1-31
Fourth paragraph
Month
1-12
Section 5
The day of the week. 0 indicates Sunday.
0-6
Name: crontab
Permission: All Users
Usage:
Crontab [-u user] File
Crontab [-u user] {-L |-r |-e}
Note:
Crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set.
Meal count:
-E: Execute the text editor to set the time table. The preset text editor is vi. If you want to use another text editor, set the visual environment variable to specify the Text Editor (for example, setenv visual Joe)
-R: Delete the current time table.
-L: list the current time table
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
You can also store all settings in the file first, and use crontab file to set the time table.
Example:
Run the command/bin/ls once every 0th minutes of every hour every month:
0 7 ***/bin/ls
During October 11, December, execute/usr/bin/backup every 20 minutes from to every day:
0 6-12/3*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/dev/null 2> & 1
For example, if the content of your crontab file is 29 19 *** echo its dinner time, the system displays 'its dinner time' at every day'
Example (create A cron process, and input the current time in test.txt every minute ):
1. log on to Linux as a common user (I use centos4.1)
2. $ crontab-e
Note: The default editor of the system is vim. If not, add the following shell:
$ Editor = vi
$ Export Editor
3. Enter "*/1 ***** date> $ home/test.txt", save and exit Vim
4. $ su Root
5. $ CD/etc/init. d
6 ../crond restart
Let's take a look at several specific examples:
● 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 the crond resident command that executes the LS command task scheduling at on the first, 11th, 21st, and 31st of each month.
Crond is a Linux Command Used to regularly execute programs. After the operating system is installed, the task scheduling command is started by default. The crond command periodically checks whether there is any job to be executed every minute. If there is any job to be executed, the job is automatically executed. Linux task scheduling mainly includes the following two types:
1. work performed by the system: work to be performed periodically by the system, such as backing up system data and clearing Cache
2. Personal Work: The work that a user regularly performs, such as checking whether there are new emails on the email server every 10 minutes. This work can be set by each user.
Crontab is a scheduled task trigger in Unix systems. Its user permissions are recorded in the following two files:
File
Description
/Etc/cron. deny
Users listed in this file cannot use the crontab command.
/Etc/cron. allow
Users listed in this file can use the crontab command
/Var/spool/cron/
Is the crontab file of all users
/Var/spool/cron/crontabs
/Var/spool/cron/crontabs
The crontab command is in the following format:Crontab-L |-r |-E |-I [username]The parameter meanings are shown in table 1:
Parameter Name
Description
Example
-L
Displays the contents of your crontab file.
Crontabl-l
-I
Prompt before deleting the crontab file
Crontabl-ri
-R
Delete a user's crontab file from the crontab directory
Crontabl-R
-E
Edit the user's crontab file
Crontabl-e
The crontab file created by the user is saved in/var/spool/cron, and its file name is consistent with the user name.
The format is divided into six segments. The first five segments are time sets, and the sixth segment is the command segment to be executed,
The format is as follows :*****
The meanings of the time period are shown in table 2:
Segment
Description
Value Range
Section 1
Minutes
0-59
Section 2
Represents the hour
0-23
Section 3
Represents a date
1-31
Fourth paragraph
Month
1-12
Section 5
The day of the week. 0 indicates Sunday.
0-6
Name: crontab
Permission: All Users
Usage:
Crontab [-u user] File
Crontab [-u user] {-L |-r |-e}
Note:
Crontab is used to allow users to execute programs at a fixed time or interval. In other words, it is similar to the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set.
Meal count:
-E: Execute the text editor to set the time table. The preset text editor is vi. If you want to use another text editor, set the visual environment variable to specify the Text Editor (for example, setenv visual Joe)
-R: Delete the current time table.
-L: list the current time table
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
You can also store all settings in the file first, and use crontab file to set the time table.
Example:
Run the command/bin/ls once every 0th minutes of every hour every month:
0 7 ***/bin/ls
During October 11, December, execute/usr/bin/backup every 20 minutes from to every day:
0 6-12/3*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/dev/null 2> & 1
For example, if the content of your crontab file is 29 19 *** echo its dinner time, the system displays 'its dinner time' at every day'
Example (create A cron process, and input the current time in test.txt every minute ):
1. log on to Linux as a common user (I use centos4.1)
2. $ crontab-e
Note: The default editor of the system is vim. If not, add the following shell:
$ Editor = vi
$ Export Editor
3. Enter "*/1 ***** date> $ home/test.txt", save and exit Vim
4. $ su Root
5. $ CD/etc/init. d
6 ../crond restart
Let's take a look at several specific examples:
● 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.