shell 定時任務 Linux 定時任務 crontab

crontab命令是linux自帶的定時任務工具
正常系統安裝時自帶這個命令的,如果執行命令返回命令不存在,則通過如下步驟安裝
crond服務

安裝crontab:

yum install crontabs

服務操作說明:
centos6或redhat6
/sbin/service crond start //啓動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啓服務
/sbin/service crond reload //重新載入配置

centos7或redhat7
systemctl start  crond//啓動服務
systemctl  stop crond //關閉服務
systemctl  restart  crond //重啓服務
systemctl  reload  crond //重新載入配置

查看crontab服務狀態:

service crond status

手動啓動crontab服務:

service crond start

查看crontab服務是否已設置爲開機啓動,執行命令:

ntsysv

加入開機自動啓動:
centos6或redhat6
chkconfig –level 35 crond on

centos7或redhat7
systemctl enable crond 

設定針對當前用戶的定時任務

crontab -e

命令進入crontab文件的編輯框
在這裏插入圖片描述
按回車進入後如圖(正常情況下應該是空的,我這裏已經添加了命令)
在這裏插入圖片描述
我的文件中命令是這樣的

0 0 * * * /home/nmon_x86_64_centos7 -t -s30 -c 2880

其中前邊的 0 0 * * *

分鐘 小時 星期 命令
0 0 * * * *

表示每天00:00執行命令,後邊/home/nmon_x86_64_centos7 -t -s30 -c 2880,是我使用的nmon監控工具的啓動命令。

分鐘 - 從0到59的整數
小時 - 從0到23的整數
日- 從1到31的整數 (必須是指定月份的有效日期)
月 - 從1到12的整數 (或如Jan或Feb簡寫的月份)
星期- 從0到7的整數,0或7用來描述週日 (或用Sun或Mon簡寫來表示)

設定針對系統的任務
編輯/etc/crontab 文件
在這裏插入圖片描述
文件中有英文說明,
我的命令如下

  0  0  *  *  * root  /home/nmon_x86_64_centos7 -t -s30 -c 2880
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章