crontab 循環執行的工作排程。
[root@localhost csie]# cat /etc/cron.allow
mail
[root@localhost csie]# cat /etc/cron.deny
cat: /etc/cron.deny: No such file or directory
[test @test test]# crontab [-u user] [-l | -e | -r]
參數說明:
-u user :只有 root 能下達的參數,視察或編譯其他使用者的 crontab 內容
-l :列出 crontab 的內容
-e :編輯 crontab 的內容
-r :刪除 crontab 的內容
[root@dywOffice dywang]# crontab -e
# min(0-59) hours(0-23) day(1-31) month(1-12) dow(0-6) command
0 0 * * 6 /backup/sysbackup
數字代表的意義
分鐘
小時
日期
月份
週
範圍
0-59
0-23
1-31
1-12
0-6 (0或7為星期天)
特殊字符
代表意義
*
代表任何時刻都接受。
'
代表分隔時段。
例如:在 0300 及 0600 時工作,則
0 3,6 * * * command
-
代表一段時間範圍內。
例如:在 0800 到 1200 之間每小時的 20 分都進行工作,
則
20 8-12 * * * command
/n
每隔
n
單位間隔。
例如每 5 分鐘進行一次,則
*/5 * * * * command
[root@dywOffice dywang]# crontab -l
# min(0-59) hours(0-23) day(1-31) month(1-12) dow(0-6) command
0 0 * * 6 /backup/sysbackup
[root@dywOffice dywang]# crontab -r
[root@dywOffice dywang]# crontab -l
no crontab for root
##以root權限將使用者 csie 加入/etc/cron.allow
[root@localhost csie]# vi /etc/cron.allow
mail
csie
##以使用者 csie 帳號編輯 crontab
[csie@localhost csie]$ crontab -e
###或 root 直接幫 csie 編輯 crontab
[root@localhost csie]# crontab -u csie -e
# min(0-59) hours(0-23) day(1-31) month(1-12) dow(0-6) command
30 1 * * 1 /home/csie/crontest
## 重新啟動 crond 服務
[root@localhost csie]# /etc/rc.d/init.d/crond restart