当前位置:网站首页>Crontab scheduled task common commands
Crontab scheduled task common commands
2022-06-27 22:05:00 【Technical column of qingpingle】
One 、 Common commands

1、 see crontab Task list
crontab -l
2、 edit crontab Scheduled tasks
crontab -e
3、 Delete crontab Timing task
crontab -r
4、 Relevant command :
systemctl start crond.service # Start the service
systemctl stop crond.service # Close the service
systemctl status crond.service # View service status
systemctl restart crond.service # Restart the service
Two 、 Timed syntax
crontab A time expression :
The basic format :
* * * * * command
branch when Japan month Zhou command
Let's start with an example . Every morning 1:00 Execute the backup program :0 1 * * * /root/backup.sh . among /root/backup.sh This is the script path , To use absolute paths , For the previous date format, please look directly at the figure below 
crontab And operators , It needs to be used to realize some complex time setting . Operators have :
1、* All numbers in the range , On behalf of all .
2、/ How many numbers are passed , Represents every n Long-term .
3、- from X To Z , For a period of time .
4、, Hash numbers , Represents splitting multiple values .
If you still don't understand the code formula , You can use this online Cron Expression generator :http://cron.qqe2.com/
3、 ... and 、20 Classic examples
Remember to replace it with your own script path . Please add... To the first line of the corresponding script #!/bin/bash, Otherwise, the script cannot be executed in the scheduled task .
example 1: Every time 1 Once per minute
* * * * * /root/backup.sh
example 2: At the end of every hour 3 Minutes and the 15 Once per minute
3,15 * * * * /root/backup.sh
example 3: Daily 8 Point to 11 Point of the first 3 And the 15 Once per minute
3,15 8-11 * * * /root/backup.sh
example 4: Every other morning 8 Point to 11 Point of the first 3 And the 15 Once per minute
3,15 8-11 */2 * * /root/backup.sh
example 5: One morning a week 8 Point to 11 Point of the first 3 And the 15 Once per minute
3,15 8-11 * * 1 /root/backup.sh
example 6: Every night 21:30 Do it once
30 21 * * * /root/backup.sh
example 7: monthly 1、10、22 Japanese 4 : 45 Do it once
45 4 1,10,22 * * /root/backup.sh
example 8: Every Saturday 、 Sunday's 1 : 10 Do it once
10 1 * * 6,0 /root/backup.sh
example 9: Every day 18 : 00 to 23 : 00 Between every 30 Once per minute
0,30 18-23 * * * /root/backup.sh
example 10: Every Saturday night 23: 00 pm Do it once
0 23 * * 6 /root/backup.sh
example 11: Every hour
* */1 * * * /root/backup.sh
example 12: Every night 23 From o'clock to the next morning 7 Between points , It is performed every hour
* 23-7/1 * * * /root/backup.sh
example 13: On the first day of each week ( That is, every Sunday night 24:00 Start execution ).
@weekly /root/backup.sh
example 14: Monthly 15 Once a day .
0 11 15 * * /root/backup.sh
example 15: On the first day of each month ( I.e. monthly 1 Early morning 0 Start at ).
@monthly /root/backup.sh
example 16: Execute once in the specified month ( stay 1 month ,4 The month and 6 Every night in June 0 Click to execute once ).
0 0 * jan,apr,jun * /root/backup.sh
example 17: Execute once after restart .
@reboot /root/backup.sh
example 18: Send an email notification after the scheduled task is executed .
MAILTO="raj"
1 1 * * * /root/backup.sh
example 19: Appoint shell ( The default is /bin/bash)
SHELL=/bin/sh
1 1 * * * /root/backup.sh
example 20: Specify environment variables .
PATH=/sbin:/bin:/usr/sbin:/usr/bin
1 1 * * * /root/backup.sh
边栏推荐
- 开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
- GBase 8a的create database 会被查询耗时很长怀疑卡住的现象分析
- QT base64 encryption and decryption
- 年薪50W+的测试大鸟都在用这个:Jmeter 脚本开发之——扩展函数
- [LeetCode]30. Concatenate substrings of all words
- Express e stack - small items in array
- [LeetCode]161. 相隔为 1 的编辑距离
- BAT测试专家对web测试和APP测试的总结
- Golang uses regularity to match substring functions
- Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)
猜你喜欢

读写分离-Mysql的主从复制

Process control task

Go from introduction to actual combat - task cancellation (note)

Burp suite遇到的常见问题

win11桌面出現“了解此圖片”如何删除
![[leetcode] dynamic programming solution partition array ii[arctic fox]](/img/a1/4644206db3e14c81f9f64e4da046bf.png)
[leetcode] dynamic programming solution partition array ii[arctic fox]
How to design an elegant caching function

Open source technology exchange - Introduction to Chengying, a one-stop fully automated operation and maintenance manager

STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app

Luogu p5706 redistributing fertilizer and house water
随机推荐
[leetcode] dynamic programming solution partition array i[red fox]
Gbase 8A OLAP analysis function cume_ Example of dist
Experience sharing of meituan 20K Software Test Engineers
[LeetCode]515. 在每个树行中找最大值
∫(0→1) ln(1+x) / (x² + 1) dx
BAT测试专家对web测试和APP测试的总结
Installing Oracle11g under Linux
Management system itclub (Part 2)
Acwing week 57 longest continuous subsequence - (binary or tree array)
Go from introduction to actual combat - execute only once (note)
Special tutorial - Captain selection game
[LeetCode]30. Concatenate substrings of all words
"Apprendre cette image" apparaît sur le Bureau win11 comment supprimer
GBase 8a OLAP分析函数 cume_dist的使用样例
∫(0→1) ln(1+x) / (x ² + 1) dx
真香,自从用了Charles,Fiddler已经被我彻底卸载了
matlab查找某一行或者某一列在矩阵中的位置
01 golang environment construction
win11桌面出现“了解此图片”如何删除
美团20k软件测试工程师的经验分享