The crontab command in the Linux command is mainly used to execute periodic scheduled tasks. It is similar to the at command. In addition, the crontab command has other usages. The following small series will give you a detailed introduction to the Linux crontab command. The usage, let's learn together.
The at command is for a task that runs only once (see How does the system home Linux use the at command to perform tasks), the routine running tasks for looping, and the linux system is cron (crond). Service to control. There are a lot of planned work on the Linux system, so this system service is started by default. In addition, since the user can also set the scheduled tasks themselves, the Linux system also provides a command for the user to control the scheduled tasks: the crontab command.
First, crond introduction
crond is a daemon used by linux to periodically perform certain tasks or wait for certain events, similar to the scheduled tasks under windows, when installing After the operating system is completed, this service tool will be installed by default, and the crond process will be started automatically. The crond process periodically checks whether there are tasks to be executed every minute. If there are tasks to be executed, the task is automatically executed.
Task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling.
System Task Scheduling: The work that the system periodically performs, such as writing cached data to the hard disk, log cleaning, and so on. There is a crontab file in the /etc directory. This is the configuration file for system task scheduling.
The /etc/crontab file includes the following lines:
The code is as follows:
[root@localhost ~]# cat /etc/crontab
SHELL =/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=“”HOME=/
# Run-parts
51 * * * * root run-parts /etc/cron.hourly
24 7 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[root@localhost ~]#
The first four lines are used to configure the environment variables for the crond task to run. The first line of the SHELL variable specifies which shell the system will use. Here is bash. The second line of the PATH variable specifies the path to the system execution command. The third line MAILTO variable specifies that the task execution information of crond will be sent to the root user by email. If the value of the MAILTO variable is empty, it means that the task execution information is not sent to the user. The HOME variable of the fourth line specifies that the command is executed. Or the main used when the script Record. The meanings indicated in lines 6 to 9 will be detailed in the next section. I won’t say more here. User task scheduling: The tasks that users perform regularly, such as user data backup, timed email reminders, and so on. Users can use the crontab tool to customize their own scheduled tasks. All user-defined crontab files are saved in the /var/spool/cron directory. Its file name is the same as the user name.
User Permissions File:
File:
The code is as follows:
/etc/cron.deny
Description:
The users listed in this file are not allowed to use the crontab command
File:
The code is as follows:
/etc/cron.allow
Description:
The users listed in this file are allowed to use the crontab command
File:
The code is as follows:
/var/spool/cron/
Description:
The directory where all user crontab files are stored, named after the user name
The meaning of the crontab file:
The crontab file created by the user, each Each row represents a task. Each field of each row represents a setting. Its format is divided into six fields. The first five segments are time setting segments, and the sixth segment is the command segment to be executed. The format is as follows:
Previous123456Next page Total 6 pages
After booting, the Ubuntu screen shows the maximum brightness. After re-adjusting t
Linux swap partitions similar to Windows virtual memory, in the case of insufficient hard disk space
texmaker is an editing tool with a latex editing environment, and after installing texlive, how to i
There are thousands of files in the computer system. If they are not classified, th
How does the Linux system send mail?
CentOS system installation using Subversion method
Linux system grep command operation example summary
What should I do if the error occurs when CentOS 5.4 adds or removes an application?
How CentOS installs Monitorix tools
How to use the Linux cd command?
What should I do if there are garbled characters in Linux Chinese characters?
Ubuntu configuration and use of MPI method
Ubuntu 14.04 prohibits the apport error report window startup method
Linux tips for viewing directory content
Introduction to the syntax of the bzip2 command in Linux system
Win10 taskbar volume icon is gone, what to do
Win7 system uses 360 browser to log in to the mailbox
Linux lftp connection ftp server upload download command
What if win7 task manager stops running
What are the formats for counting images to help you become a designist
How to solve /usr/bin/ld: cannot find -lxxx error
Method for cleaning Metro application cache under Win8 system
How to use the vlookup function in Excel 2013?