linux centos 7定时任务添加,CentOS 7 cron服务 定时任务使用方法
CentOS 7 cron服務(wù) 定時(shí)任務(wù)使用方法
cron服務(wù)是Linux內(nèi)置服務(wù),默認(rèn)不會(huì)開(kāi)機(jī)自動(dòng)啟動(dòng)。可用以下命令啟動(dòng)和停止服務(wù),也可以設(shè)置成開(kāi)機(jī)啟動(dòng):
systemctl?start?crond
啟動(dòng)cron服務(wù)
systemctl?stop?crond
停止cron服務(wù)
systemctl?restart?crond
重啟cron服務(wù)
systemctl enable crond.service
設(shè)置cron開(kāi)機(jī)啟動(dòng)
查看當(dāng)前crontab,輸入 crontab -l
編輯當(dāng)前crontab,輸入 crontab -e
刪除當(dāng)前crontab,輸入 crontab? -r
添加定時(shí)任務(wù)
crontab?-e
0?*/1?*?*?*?command0?*/2?*?*?*?command
查詢?nèi)蝿?wù)是否添加:
crontab?-l?-u?root
#查看root用戶
任務(wù)添加格式 :
* * * * * command
分 時(shí) 日 ? 月 ? 周 ? 命令
第1列表示分鐘1~59? 每分鐘用*或者 */1表示
第2列表示小時(shí)0~23(0表示0點(diǎn))
第3列表示日期1~31
第4列表示月份1~12
第5列標(biāo)識(shí)號(hào)星期0~6(0表示星期天)
第6列要執(zhí)行的命令
crontab文件的例子:
30 21 *? *? *? systemctl restart httpd.service
表示每晚21:30重啟apache。
45 4 1,10,22? *? * systemctl restart httpd.service
表示每月1、10、22日的4 : 45重啟apache。
10 1 * * 6,0 systemctl restart httpd.service
表示每周六、周日的1 : 10重啟apache。
0,30 18-23 * * * systemctl restart httpd.service
表示在每天18 : 00至23 : 00每隔30分鐘重啟apache。
0 23 * * 6 systemctl restart httpd.service
表示星期六晚上11點(diǎn)重啟apache。
* */1 * * * systemctl restart httpd.service
每一小時(shí)重啟apache
* 23-7/1 * * * systemctl restart httpd.service
晚上11點(diǎn)到早上7點(diǎn)之間,每隔一小時(shí)重啟apache
0 11 4 * mon-wed systemctl restart httpd.service
每月的4號(hào)與每周一到周三的11點(diǎn)重啟apache
0 4 1 jan * systemctl restart httpd.service表示一月一號(hào)的4點(diǎn)重啟apache
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的linux centos 7定时任务添加,CentOS 7 cron服务 定时任务使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 将一个数组中的值按逆序重新排放。_六十五
- 下一篇: 用gnuplot画出c产生数据的波形图