This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13083|Reply: 1

[linux] CentOS 7 uses crontab to perform tasks at regular intervals

[Copy link]
Posted on 6/27/2020 3:27:42 PM | | | |
What is crond?

CronTab and Crontab are inseparable. crontab is a command commonly found in Unix and Unix-like operating systems to set instructions to be executed periodically. This command reads instructions from a standard input device and stores them in a "crontab" file for later reading and execution. The word is derived from the Greek word chronos (χρόνος), which originally meant time.

And crond is its guardian process. The cron service is a scheduled service that allows you to add or edit tasks that need to be scheduled to be executed through the crontab command.

Common commands:

Set the script that needs to be executed

There are two ways to add a scheduling task:

1) Enter crontab -e on the command line and then add the corresponding task, and the wq save exits.
2) Directly edit the /etc/crontab file, i.e. vi /etc/crontab, and add the corresponding task.
The crontab -e configuration is for a certain user, while editing /etc/crontab is a task for the system

View the scheduling task

crontab -l // lists all current scheduling tasks
crontab -l -u jp // Lists all scheduling tasks for the user's jp

Common commands

crontab -u // sets the cron service for a certain user
crontab -l // lists the details of a user's cron service
crontab -e // Edit a user's cron service
crontab -i // print prompt, enter a confirmation message such as yes
crontab -r // to remove all task scheduling work

cron format



Added timed tasks

Let's test the crontab service with an example where every minute we create a blank file named after the current year, month, day, hour, and minute in the /root/test_itsvse directory

Execute the command:

Here is actually a vim editor, enter i to edit, as follows:

After the addition is successful, we get a hint for the last row of installing new crontab

Note that "%" in the crontab file has the functions of ending the command line, wrapping the line, and redirecting, and adding the "\" symbol to escape in front, otherwise the "%" symbol will perform its function of ending the command line or wrapping the line, and the subsequent content will be sent as standard input to the previous command.

Reload the configuration


View Scheduled Tasks

View logs


The logs are arranged by day, the most recent log, look at the /var/log/cron file

The renderings are as follows:



(End)





Previous:OpenLDAP custom objectclass and properties
Next:VS 2019 (Visual Studio) code cleanup
Posted on 11/15/2022 6:20:52 PM |
Learn it
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com