crontab 可以讓系統在指定時間自動執行你要做的動作。
crontab -u:設定某使用者的 cron 服務(root 執行時通常需要此參數)。
crontab -l:列出使用者的 cron 內容。
crontab -r:刪除使用者的 cron 服務。
crontab -e:編輯使用者的 cron 服務(編輯模式同 vi)。
* * * * * command 分 時 日 月 周 命令
第 1 列分鐘 1~59(每分鐘用 * 或 */1)、第 2 列小時 0~23、第 3 列日 1~31、第 4 列月 1~12、第 5 列星期 0~6(0 為週日)、第 6 列為要執行的命令。
30 21 * * * /etc/init.d/smb restart # 每晚 21:30 重啟 smb 45 4 1,10,22 * * /etc/init.d/smb restart # 每月 1、10、22 日 4:45 10 1 * * 6,0 /etc/init.d/smb restart # 每週六、日 1:10 0,30 18-23 * * * /etc/init.d/smb restart # 每天 18:00~23:00 每 30 分鐘 0 23 * * 6 /etc/init.d/smb restart # 每週六 23:00 0 */1 * * * /etc/init.d/smb restart # 每一小時 0 23-7/1 * * * /etc/init.d/smb restart # 晚 11 點到早 7 點每小時 0 11 4 * mon-wed /etc/init.d/smb restart # 每月 4 號及週一至三 11 點 0 4 1 jan * /etc/init.d/smb restart # 一月一號 4 點