關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • Unix Crontab 簡介

    Posted on March 23rd, 2006 Sam Tang No comments

    Crontab 是在 Unix Like 系統下設定排程自動執行的工具,最常用到的地方是備份。而 crontab 有 4 個不同的參數,作用分別是:

    crontab -e 編輯 crontab 檔案,如果檔案不存在則會自動建立。
    crontab -l 顯示 crontab 檔案內容。
    crontab -r 刪除 crontab 檔案。
    crontab -v 顯示上一次編輯 crontab 的時間,但不是所有系統適用。

    編輯 crontab
    在指令模式輸入 "crontab -e" 便會用預設編輯器打開 crontab 檔案,排程的格式為每一行一個排程,而每一個排程的內容會是:

    分鐘   小時   日   月   星期   執行指令

    以下例子會在每晚零時零分自動執行 /root/sync_time.sh,而因為不想儲存輸出結果,所以將輸出放到 /dev/null。

    00 00 * * * /root/sync_time.sh > /dev/null 2>&2

    當編輯好 crontab 檔案後,將它儲存即可。


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word