爲linux添加計劃任務(定時腳本)

因爲經常要在機房上實驗課,便想在機房遠程自己的電腦。

但是我們學校的ruijie是在8點才能認證的,於是便編寫了個自動執行的腳本,在8點連接上ruijie。

環境:ubuntu12.04

首先,編寫一個腳本test.sh,保存在/home/nevermore目錄,代碼如下:

#!/bin/sh

sudo mentohust

echo success

這個腳本用於啓動ruijie

接着,我們打開/etc/crontab,我們可以看到如下內容:

# m h dom mon dow user command
17 * * * * root    cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )


其中,m代表分鐘,h代表小時,dom爲day of month mon爲月份 dow爲day of week,我們在最後一行添加如下代碼:

10 8       * * * root sudo /home/nevermore/test.sh

代表 系統將在每天的8點10分執行該目錄下的test.sh腳本。


哈哈,ok,到此就完成操作啦~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章