Generally speaking, under CentOS, crontab can be used to process timed tasks.
1. Installation
yum install crontabs
2. Timing syntax description
In corntab, a line of code is a timed task, and its grammatical structure can be understood through this diagram.
The meaning is as follows
* 代表取值范围内的数字
/ 代表"每"
- 代表从某个数字到某个数字
, 代表离散的取值(取值的列表)
Some commonly used time is written as follows:
* * * * * //每分钟执行
* */4 * * * //每4小时执行,每一分钟都会执行
0 */4 * * * //每4小时执行,只执行一次
0 4 * * * //每天4点执行
0 12 */2 * * //每2天执行一次,在12点0分开始运行
* * * * 0 //每周日执行
* * * * 6,0 //每周六、日执行
5 * * * * //每小时的第5分钟执行
3. Configure the script to be executed regularly
Since the python script needs to be executed regularly, the following command should be used:
python xxx.py
4. Note: Use absolute path to write the command, otherwise the timing operation will fail
5. View the list of timed tasks in the current system
crontab -l
6. Edit
crontab -e
7. Add a new record
00 * * * * /usr/bin/python3 /root/interface/blog_ETH.py
After completion, you can restart the crontab service.
service crond restart