當(dāng)前位置:
首頁(yè) >
Linux下Crontab定时执行命令
發(fā)布時(shí)間:2024/4/11
53
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Linux下Crontab定时执行命令
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Linux下Crontab定時(shí)執(zhí)行命令
目錄
1. Crontab概述及安裝
1. Crontab指令是Linux下執(zhí)行定時(shí)任務(wù)的一個(gè)命令。
2. 檢查服務(wù)器是否安裝了crontab
rpm -qa | grep crontab3. 如果沒有安裝好,執(zhí)行安裝命令
4. 安裝好久可以啟動(dòng)和配置服務(wù)
service crond start //啟動(dòng)服務(wù) service crond stop //關(guān)閉服務(wù) service crond restart //重啟服務(wù) service crond reload //重新載入配置 service crond status //查看crontab服務(wù)狀態(tài)5. 設(shè)置開機(jī)自啟動(dòng)
chkconfig --level 345 crond on2. Crontab規(guī)則
1. crontab文件格式
* * * * * command分 時(shí) 日 月 周(幾) 命令2. 特殊字符解釋
3. 練習(xí)
在目錄下新建一個(gè)shell文件:test.sh,寫入
#!/bin/bashecho "hello world!"給test.sh可執(zhí)行權(quán)限
chmod 755 test.sh執(zhí)行contab -e編寫定時(shí)任務(wù),每分鐘執(zhí)行一次test.sh腳本。
*/1 * * * * /a8root/home/lijinwang/test/test.sh >> /a8root/home/lijinwang/test/test.log結(jié)果。
3. 常見例子
每月每天凌晨3點(diǎn)30分和中午12點(diǎn)20分執(zhí)行test.sh腳本
30 3,12 * * * /root/test.sh >> /root/test.log每月每天每隔6小時(shí)的每30分鐘執(zhí)行test.sh腳本
30 */6 * * * /root/test.sh >> /root/test.log每月每天早上8點(diǎn)到下午18點(diǎn)每隔2小時(shí)的每30分鐘執(zhí)行test.sh腳本
30 8-18/2 * * * /root/test.sh >> /root/test.log每月每天晚上21點(diǎn)30分執(zhí)行test.sh腳本
30 21 * * * /root/test.sh >> /root/test.log每月1號(hào)、10號(hào)、22號(hào)凌晨4點(diǎn)45分執(zhí)行test.sh腳本
45 4 1,10,22 * * /root/test.sh >> /root/test.log8月份周一、周日凌晨1點(diǎn)10分執(zhí)行test.sh腳本
10 1 * 8 6,0 /root/test.sh >> /root/test.log每月每天每小時(shí)整點(diǎn)執(zhí)行test.sh腳本
00 */1 * * * /root/test.sh >> /root/test.log總結(jié)
以上是生活随笔為你收集整理的Linux下Crontab定时执行命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Go语言中*和的区别
- 下一篇: Linux的内存理解