linux crontab 定時任務使用
阿新 • • 發佈:2021-12-27
1 centos 安裝
yum install crontabs
2 編輯配置
crontab -e
例項
1 0 * * * /opt/backup/back_mysql.sh >> /opt/backup/backup.log #(每天的0點01分執行 */20 * * * * /usr/bin/python /opt/switch_agent_pool/switch_ip.py #20分鐘執行一次
例項1:每1分鐘執行一次myCommand * * * * * myCommand 例項2:每小時的第3和第15分鐘執行 3,15 * * * * myCommand 例項3:在上午8點到11點的第3和第15分鐘執行 3,15 8-11 * * * myCommand 例項4:每隔兩天的上午8點到11點的第3和第15分鐘執行 3,15 8-11 */2 * * myCommand 例項5:每週一上午8點到11點的第3和第15分鐘執行 3,15 8-11 * * 1 myCommand 例項6:每晚的21:30重啟smb 30 21 * * * /etc/init.d/smb restart 例項7:每月1、10、22日的4 : 45重啟smb 45 4 1,10,22 * * /etc/init.d/smb restart 例項8:每週六、週日的1 : 10重啟smb 10 1 * * 6,0 /etc/init.d/smb restart 例項9:每天18 : 00至23 : 00之間每隔30分鐘重啟smb 0,30 18-23 * * * /etc/init.d/smb restart 例項10:每星期六的晚上11 : 00 pm重啟smb 0 23 * * 6 /etc/init.d/smb restart 例項11:每一小時重啟smb 0 */1 * * * /etc/init.d/smb restart 例項12:晚上11點到早上7點之間,每隔一小時重啟smb 0 23-7/1 * * * /etc/init.d/smb restart
命令
service crond start //啟動服務 service crond stop //關閉服務 service crond restart //重啟服務 service crond reload //重新載入配置 service crond status //檢視服務狀態