CentOS下crontab運行定時任務的簡單樣本

來源:互聯網
上載者:User


首先,開啟命令列。如果沒有安裝crontab的話

1,先安裝crontab:

yum install crontabs

說明:

/sbin/service crond start //啟動服務
/sbin/service crond stop //關閉服務
/sbin/service crond restart //重啟服務
/sbin/service crond reload //重新載入配置
/sbin/service crond status //察看當前crond運行狀態

2,以普通使用者登入linux系統。運行crond,確保crond當前正在運行


/sbin/service crond start //啟動服務

3,進入到crontab的VI編譯器中

crontab –e

說明:系統預設的編輯器是VIM,如果不是請加上以下shell:


EDITOR=vi
export EDITOR

基本格式:

* *  *  *  *  command
分 時 日 月 周  命令

4,開啟VI編譯器後,輸入一下內容

*/1 * * * * date >> $HOME/test1.txt

儲存並且退出,esc+shift+;


5,到這裡,在你案頭的Home檔案夾就會多出一個檔案夾

如果不行的話,重啟一下

su root
cd /etc/init.d
./crond restart

開啟案頭上的Home檔案,裡面就會有一個test.txt檔案,開啟就能看到每隔一分鐘就會寫入時間


crontab規則詳細執行個體

1、每天6:00執行

0 6 * * * root /home/www.111cn.net/osyunwei.sh

2、每周六淩晨4:00執行

0 4 * * 6 root /home/www.111cn.net/osyunwei.sh

3、每周六淩晨4:05執行

5 4 * * 6 root /home/www.111cn.net/osyunwei.sh

4、每周六淩晨4:15執行

15 4 * * 6 root /home/www.111cn.net/osyunwei.sh

5、每周六淩晨4:25執行

25 4 * * 6 root /home/www.111cn.net/osyunwei.sh

6、每周六淩晨4:35執行

35 4 * * 6 root /home/www.111cn.net/osyunwei.sh

7、每周六淩晨5:00執行

5 * * 6 root /home/www.111cn.net/osyunwei.sh

8、每天8:40執行

40 8 * * * root /home/www.111cn.net/osyunwei.sh

9、每天8:30執行

30 8 * * * root /home/www.111cn.net/osyunwei.sh

10、每周一到周五的11:41開始,每隔10分鐘執行一次

41,51 11 * * 1-5   root /home/www.111cn.net/osyunwei.sh

1-59/10 12-23 * * 1-5   root /home/www.111cn.net/osyunwei.sh

11、在每天的10:31開始,每隔2小時重複一次

31 10-23/2 * * * root   /home/www.111cn.net/osyunwei.sh

12、每天15:00執行

0 15 * * *  root /home/www.111cn.net/osyunwei.sh

13、每天的10:30開始,每隔2小時重複一次

30 10-23/2 * * * root  /home/www.111cn.net/osyunwei.sh

14、每天15:30執行

30 15 * * *  root /home/www.111cn.net/osyunwei.sh

15、每天17:50執行

50 17 * * *  root /home/www.111cn.net/osyunwei.sh

16、每天8:00執行

0 8 * * *  root  /home/www.111cn.net/osyunwei.sh

17、每天18:00執行

0 18 * * *  root  /home/www.111cn.net/osyunwei.sh

18、每天8:30執行

系統營運 www.111cn.net 溫馨提醒:qihang01原創內容著作權,轉載請註明出處及原文連結

30 8 * * *  root  /home/www.111cn.net/osyunwei.sh

19、每天20:30

30 20 * * *  root /home/www.111cn.net/osyunwei.sh

20、每周一到周五2:00

0 2 * * 1-5 root /home/www.111cn.net/osyunwei.sh

21、每周一到周五9:30

30 9 * * 1-5 root /home/www.111cn.net/osyunwei.sh

22、每周一到周五8:00,每周一到周五9:00

0 8,9 * * 1-5  root /home/www.111cn.net/osyunwei.sh

23、每天23:59

59 23 * * *  root  /home/www.111cn.net/osyunwei.sh

24、每周六23:59

59 23 * * 6  root    /home/www.111cn.net/osyunwei.sh

25、每天0:30

30 0 * * *  root  /home/www.111cn.net/osyunwei.sh

26、每周一到周五9:25到11:35之間、13:00到15:00之間,每隔10分鐘運行一次

25,35,45,55  9 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

5-59/10  10 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

5,15,25,35  11 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

*/10  13-15 * * 1-5  root   /home/www.111cn.net/osyunwei.sh

27、每周一到周五8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分別執行一次

30,50 8 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

30 9 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

*/30 10-11 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

30 13 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

0,30 14-15 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

28、每天23:50執行

50 23 * * *  root  /home/www.111cn.net/osyunwei.sh

29、每天10:00、16:00執行

0 10,16 * * *  root /home/www.111cn.net/osyunwei.sh

30、每天5:30執行

30 5 * * *  root  /home/www.111cn.net/osyunwei.sh

31、每周一到周五9:30執行

30 9 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

32、每周一到周五13:00執行

0 13 * * 1-5  root  /home/www.111cn.net/osyunwei.sh

33、每天7:51執行

51 7 * * *  root /home/www.111cn.net/osyunwei.sh

34、每天7:53、12:40分別執行一次

53 7 * * *  root /home/www.111cn.net/osyunwei.sh

40 12 * * *  root /home/www.111cn.net/osyunwei.sh

35、每天7:55執行

55 7 * * *  root  /home/www.111cn.net/osyunwei.sh

36、每天8:10、16:00、20:00分別執行一次

10 8 * * *  root  /home/www.111cn.net/osyunwei.sh

0 16 * * *  root  /home/www.111cn.net/osyunwei.sh

0 20 * * *  root  /home/www.111cn.net/osyunwei.sh

37、每天7:57、8:00分別執行一次

57 7 * * *  root  /home/www.111cn.net/osyunwei.sh

0 8 * * *  root  /home/www.111cn.net/osyunwei.sh

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.