[root@dywOffice dywang]# vi /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ 01 * * * * root run-parts /etc/cron.hourly %*<==每小時執行的工作 *) 02 4 * * * root run-parts /etc/cron.daily %*<==每天執行的工作 *) 22 4 * * 0 root run-parts /etc/cron.weekly %*<==每星期執行的工作 *) 42 4 1 * * root run-parts /etc/cron.monthly %*<==每個月執行的工作 *) 分 時日月週 使用者 參數 指令 ## 重新啟動crond服務 [root@dywOffice dywang]# /etc/rc.d/init.d/crond restart
MAILTO=root
:發生錯誤時將訊息傳給 root,可將 e-mail 改成自己的帳號。例如:MAILTO=dywang@mail.cyut.edu.tw
。
PATH=
:執行檔搜尋的路徑。
01 * * * * root run-parts /etc/cron.hourly
:每個小時的 01 分,系統會以 root 層級到目錄 /etc/cron.hourly
下執行所有可以執行檔。
/etc/crontab
支援之指令下達方式:
01 * * * * test mail -s test test < /home/test/test.txt
*/5 * * * * root run-parts /root/runcron
練習題