centos crontab settings

 1. The concept of
  crontab command The crontab command is used to set instructions to be executed periodically. This command reads instructions from the standard input device and stores them in the "crontab" file for later reading and execution.
The cron system scheduling process. You can use it to run jobs during off-peak load times every day, or at different times of the week or month. Cron is the main scheduling process of the system and can run jobs without manual intervention.
  The crontab command allows users to submit, edit or delete corresponding jobs. Every user can have a crontab file to save scheduling information. System administrators can prohibit or allow users to have their own crontab files through the cron.deny and cron.allow files.
 
2. Check if crontab is installed
rpm -qa | grep crontab
 
3. Start and shut down the crontab service

 
 
Four, the global configuration file
crontab exists under the /etc directory, cron.hourly, cron.daily, cron.weekly, cron.monthly, cron.d and two files crontab and cron.deny
cron.daily are executed once a day Job
cron.weekly is a job
cron that is executed once a
week.monthly is a job cron that is executed once a month.hourly is a job cron that is executed once every
hour.d is a task that the system needs to do regularly and automatically
crontab is a set timing The task execution file
cron.deny file is used to control which users are not allowed to use Crontab function
 
5. User configuration file
  Each user has its own cron configuration file, which can be edited through crontab -e. Generally, we edit the user After the cron configuration file is saved and exited, the system will automatically be stored in the /var/spool/cron/ directory, and the file is named after the user name. The cron service of linux reads /var/spool/cron every one minute, /etc/
 
crontab, all the contents under /etc/cron.d. Six, crontab file format        * command minute hour day month week command time- sharing day month week command
                           

minute: Indicates the minute, which can be any integer from 0 to 59.
hour: indicates the hour, which can be any integer from 0 to 23.
day: indicates the date, which can be any integer from 1 to 31.
month: Represents the month, which can be any integer from 1 to 12.
week: indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
command: The command to be executed, which can be a system command or a script file written by yourself.
 
7. The special character
asterisk ( ): represents all possible values. For example, if the month field is an asterisk, it means that it satisfies other fields. The command operation is executed every month after the restriction condition.
Comma (,): You can specify a list range with comma-separated values, for example, "1,2,5,7,8,9".
Middle bar (-): A middle bar between integers can be used to indicate an integer range, for example, "2-6" means "2,3,4,5,6".
Forward slash (/): You can use forward slashes to specify the time interval frequency, for example, "0-23/2" means that it will be executed every two hours. At the same time, the forward slash can be used with an asterisk, such as
/10. If it is used in the minute field, it means that it will be executed every ten minutes.
 
8. Query current user timed tasks or delete current user timed tasks

 
9. Test
. Write a test.sh script in the home directory. The script function is to copy the text of ifcfg-eth0 under /home to the /mnt directory.

Run crontab -e to write a scheduled task /5 * /home/test.sh to execute the test.sh script every 5 minutes.

 
10. Other
settings crond starts automatically when booting.

Instance

Crontab can also support system restart to automatically execute tasks @reboot /home/test.sh

Guess you like

Origin blog.51cto.com/12772149/2603709