当前位置:网站首页>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
边栏推荐
- Xiao Wang's interview training task
- [LeetCode]100. Same tree
- [leetcode] dynamic programming solution partition array i[red fox]
- [LeetCode]572. A subtree of another tree
- Installing Oracle11g under Linux
- Simulink导出FMU模型文件方法
- xpath
- win11桌面出現“了解此圖片”如何删除
- [LeetCode]30. Concatenate substrings of all words
- 不外泄的测试用例设计秘籍--模块测试
猜你喜欢

使用Jmeter进行性能测试的这套步骤,涨薪2次,升职一次

VMware virtual machine PE startup

This set of steps for performance testing using JMeter includes two salary increases and one promotion

crontab定时任务常用命令

win11桌面出现“了解此图片”如何删除

.NET学习笔记(五)----Lambda、Linq、匿名类(var)、扩展方法

How to delete "know this picture" on win11 desktop

Process control task

PCIe knowledge point -008: structure of PCIe switch

Go from introduction to practice - error mechanism (note)
随机推荐
Go from introduction to actual combat - execute only once (note)
Example of using gbase 8A OLAP function group by grouping sets
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
软件缺陷管理——测试人员必会
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图
[LeetCode]161. Edit distance of 1
Test automatique de Test logiciel - test d'interface de l'introduction à la maîtrise, apprendre un peu chaque jour
TreeSet details
regular expression
qt base64加解密
Array assignment
登录凭证(cookie+session和Token令牌)
Set code exercise
Hash table - sum of arrays
matlab查找某一行或者某一列在矩阵中的位置
Management system itclub (Part 2)
JVM memory structure when creating objects
Selenium上传文件有多少种方式?不信你有我全!
[LeetCode]30. 串联所有单词的子串
Simulink method for exporting FMU model files