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)
|