zoukankan      html  css  js  c++  java
  • Ubuntu使用crontab 使用举例

    除了这些固定值外,还可以配合星号(*),逗号(,),和斜线(/)来表示一些其他的含义:
     

     
    星号          表示任意值,比如在小时部分填写 * 代表任意小时(每小时)
     
    逗号          可以允许在一个部分中填写多个值,比如在分钟部分填写 1,3 表示一分钟或三分钟
     
    斜线          一般配合 * 使用,代表每隔多长时间,比如在小时部分填写 */2 代表每隔两分钟。所以 */1 和 * 没有区别
     

    1. * * * * *      date >> /home/postgres/time.log            # 每隔一分钟执行一次任务  
    2. 0 * * * *      date >> /home/postgres/time.log          # 每小时的0点执行一次任务,比如6:00,10:00  
    3. 6,10 * 2 * *    date >> /home/postgres/time.log      # 每个月2号,每小时的6分和10分执行一次任务  
    4. */3,*/5 * * * *  date >> /home/postgres/time.log        # 每隔3分钟或5分钟执行一次任务,比如10:03,10:05,10:06

     

    3 * * * * /home/meng/hello.sh就是:每小时的03分执行/home/meng/下的hello.sh脚本*/5 9-17 * * mon,tue,wed,thur,fri wall "Are we there yet?"
     
    5 3 * * * /usr/bin/apt-get update 就是每天的03:05执行“/usr/bin/apt-get update
     
    */5 9-17 * * mon,tue,wed,thur,fri wall "Are we there yet?" 就是在所有的工作日的(9-17点)每过5分钟出现"Are we there Yet?"
     
    #每晚的21:30重启apache。
    30 21 * * * /usr/local/etc/rc.d/lighttpd restart

    #每月1、10、22日
    45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart

    #每天早上6点10分
    10 6 * * * date

    #每两个小时
    0 */2 * * * date

    #晚上11点到早上8点之间每两个小时,早上8点
    0 23-7/2,8 * * * date

    #每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
    0 11 4 * mon-wed date

    #1月份日早上4点
    0 4 1 jan * date

  • 相关阅读:
    SVN服务器搭建(一)
    排序算法二:冒泡排序
    【LeetCode】136. Single Number
    【LeetCode】217. Contains Duplicate
    【LeetCode】189. Rotate Array
    【LeetCode】122. Best Time to Buy and Sell Stock II
    【LeetCode】26. Remove Duplicates from Sorted Array
    【LeetCode】20. Valid Parentheses
    【LeetCode】680. Valid Palindrome II
    【LeetCode】345. Reverse Vowels of a String
  • 原文地址:https://www.cnblogs.com/jamesf/p/4751485.html
Copyright © 2011-2022 走看看