Crontab是一個(gè)很方便的在unix/linux系統(tǒng)上定時(shí)(循環(huán))執(zhí)行某個(gè)任務(wù)的程序。
用 service crond status 查看 crond服務(wù)狀態(tài),如果沒有啟動(dòng)則 systemctl start crond.service啟動(dòng)它。
直接編輯crontab文件,vi /etc/crontab,會(huì)看到一個(gè)crontab的例子:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
不指定具體的時(shí)間用*號替代,用空格區(qū)分時(shí)間參數(shù),最后是到時(shí)要執(zhí)行的操作。
如:在每天的下午17:01執(zhí)行一次reboot重啟服務(wù)器操作 :
1 17 * * * root reboot
然后重啟服務(wù)
systemctl restart crond.service