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