1. Overview:
Crond is a daemon that is used to periodically perform certain tasks or wait for certain events under Linux, similar to Scheduled tasks under Windows, when the operating system is installed, the Service tool is installed by default and the Crond process is started automatically. The Crond process periodically checks to see if there is a task to perform and automatically executes the task if there are tasks to perform.
2. Classification of Task scheduling:
- System task scheduling: The work to be performed by the system periodically, such as writing cache data to hard disk, log cleanup, etc. In the/etc directory there is a crontab file, this is the System Task Scheduler configuration file.
The first four rows are the environment variables that are used to configure the Crond task to run
The first line of the shell variable specifies which shell the system will use, and this is bash
The second line of PATH variable specifies the path of the System execution command
The third line of the mailto variable specifies that Crond's task execution information will be emailed to the root user, and if the value of the mailto variable is null, the task execution information is not sent to the user
The four-row home variable specifies the home directory to use when executing the command or script.
The meaning of line sixth to Nineth is described in detail in the next section. There's not much to say here.
- User Task scheduling: Users to perform regular work, such as user data backup, scheduled 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.
3. Crond Service
# yum Install Crontabs
- Service Operation Instructions:
#/sbin/service Crond Start//Startup service
#/sbin/service Crond stop//Shut down service
#/sbin/service crond Restart//Restart service
#/sbin/service Crond Reload//Reload Configuration
- View Crontab Service Status:
#service crond Status
- To start the Crontab service manually:
#service Crond Start
- To see if the Crontab service is set to boot, execute the command:
#ntsysv
Add to boot auto start:
#chkconfig –level Crond on
- Terminating task scheduling
#crontab-R
- List Current task schedules
#crontab –l
4. Crontab Usage Instructions
5. Set up User Task Scheduler
#crontab –e
#输入 * * * * * ls–l/etc/>/tmp/to.txt
Note: * represents every minute, hourly, daily, monthly etc.
6. Another way to set up crontab
Create the shell file first, and then set the shell file to execute in crontab
- Change the permission type of the mytask.sh file (readable writable executable)
#chmod 744 mytask.sh
Append INPUT * * * * * */tmp/mytask.sh
- Here we can see the To1.txt file created by crontab
- View current Task Schedule
Linux under Crontab detailed