1 / 16

排程工作

排程工作. at 、 batch 、 crone. 自動執行工作. 指定執行時間 at 系統安排 batch 定期執行 crontab. at. 排定執行一次工作的時間 at 時間 [root@peace2 ~]# at 17:30 2005-04-06 at> shutdwon -h +10 "system will shutdown after 10 minutes" at> <EOT> job 1 at 2005-04-06 17:30. at. 標準輸入 at teatime 由檔案輸入 at 1730 –f works

shilah
Download Presentation

排程工作

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 排程工作 at、batch、crone

  2. 自動執行工作 • 指定執行時間 at • 系統安排 batch • 定期執行 crontab

  3. at • 排定執行一次工作的時間 • at 時間 [root@peace2 ~]# at 17:30 2005-04-06 at> shutdwon -h +10 "system will shutdown after 10 minutes" at> <EOT> job 1 at 2005-04-06 17:30

  4. at • 標準輸入at teatime • 由檔案輸入at 1730 –f works • to run a job at 4pm three days from now at 4pm + 3 days • to run a job at 10:00am on July 31 at 10am Jul 31 • to run a job at 1am tomorrow at 1am tomorrow

  5. at • 顯示排定工作 at –l atq • 刪除排定工作at –d jobnumatrm jobnum

  6. batch • 在系統負擔比較小時再執行 • 輸入方法與at相同 • executes commands when system load levels permit; in other words, when the load average drops below 0.8, or the value specified in the invocation of atrun.

  7. 定期執行-cron daemon • cron daemon 是一個常駐服務,它提供計時器的功能, 在特定時間執行程式或指令 • 每分鐘檢查一次 • 搜尋/var/spool/cron目錄, /etc/crontab檔案, /etrc/cron.d目錄 • 所有輸出會寄給使用者

  8. 若只有cron.deny,則在此檔中的使用者不可使用cron,若cron.deny為空檔,則所有人均可使用cron若只有cron.deny,則在此檔中的使用者不可使用cron,若cron.deny為空檔,則所有人均可使用cron • 若只有cron.allow,則 在此檔中的使用者才可使用cron • 若無cron.allow 和cron.deny,則只有root可使用cron;或是所有使用者均可使用,視site-dependent configuration parameters 而定.

  9. cron, crontab • crontab檔案中的每一行均指定一個指令,及執行時間 • 包含五個欄位,由左而右分別為 分 時 日 月 星期 使用者 命令 • 分   (0-59) • 時   (0-23) • 日   (1-31) • 月   (1-12) • 星期  (0-7) 0 或7 為星期日, 也可用sun、mon • 使用者 若為系統檔案時可指定使用者,    一般使用者無此欄位 • 命令  設定要執行的命令或指令

  10. 以tab或空白分開 , 代表一組數字 -代表時間範圍 * 代表所有合法數值,或不指定的欄位

  11. crontab [-u 使用者名稱] [設定檔]crontab [-u 使用者名稱] [- erl] • -e 編輯 • -r 刪除 • -l 列出 • 使用者只能處理自己的crontab 檔,以自己的帳號為檔名存放在/var/spool/cron目錄下  • 只有root可以指定username • crond指令預設會將執行結果及錯誤訊息,以E-mail的方式寄給要求執行的使用者

  12. 設定crontab • crontab –e (呼叫vi編輯) • 若要改變預設編輯器,利用變數VISUAL或EDITOR設定所需之編輯器 • 例如要將預設編輯器設為pico 在.bash_profile中加入 export VISUAL=/usr/bin/pico

  13. crontab內容 #每月1號15號檢查/home 0 0 1,15 * * fsck /home #每星期日早上6:30查詢quota資料 30 6 * * sun quota –a #每天凌晨5分執行daily.job 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 #週一~週五晚上10點通知John 0 22 * * 1-5 mail –s “It’s 10PM” john %John, %%Where are your kid ?% 23 0-23/2 * * * echo “run 23 minutes after midn, 2am, 4am…,everyday”

  14. 執行一設定檔 • 依crontab格式事先編輯好的文字檔, 例如 mycron crontab mycron

  15. 檢視crontab • root檢視系統的crontab crontab –l • root檢視使用者john的crontab crontab –u john -l

  16. 移除crontab • root移除系統的crontab crontab –r • root移除使用者john的crontab crontab –u john -r

More Related