In Centos, you can configure crontab to regularly execute tasks. the execution body can be a system command or a script written by yourself. you can also assign users to execute tasks. You can configure crontab in two ways. Method 1: Use the crontab command. for example, add a new or edit existing one. use crontab-e to enter the configuration file. At this time, the performer of crontab configuration is the current login user. if the current user is root, you need to configure it for other users, you can use crontab-e-u User
In Centos, you can configure crontab to regularly execute tasks. the execution body can be a system command or a script written by yourself. you can also assign users to execute tasks. You can configure crontab in two ways.
Method 1: Use the crontab command, for example, to add a new or edit an existing one, use:
crontab -e
You can access the configuration file. At this time, the performer of crontab configuration is the current login user. if the current user is root, you need to configure it for other users, you can use
Crontab-e-u user name or su user name crontab-e
One disadvantage of this method is that the crontab configured in the current system is not in a configuration file, which makes it inconvenient for the administrator to query the number of crontabs.
Method 2: directly add it to the/etc/crontab file, but the root identity is required. Open the file and you will see information similar to the following:
SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# | .------------- hour (0 - 23)# | | .---------- day of month (1 - 31)# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | | | |# * * * * * user-name command to be executed
To add a new crontab, you only need to add it at the end of the file.Note that the user name must be specified here, while Method 1 does not.If it is specified, it is considered as part of the command, which may lead to crontab execution failure.
If the server is managed by the root user, we recommend that you add crontab to use method 2. in this way, all the scheduled tasks in the system are together and you can see at a glance.