<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Bryan

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks

    UnixSolaris環境下建立Cron Jobs

    CronUnix, solaris工具, 允許cron精靈進程在后臺每隔一段時間自動調度運行任務。這些任務在Unix solaris環境中稱為cron jobs, Crontab(Cron)是一個文件,里面包含了要在特定時間運行的Cron的條目。

    這個文檔中覆蓋了Unix cron jobs以下幾個方面

    1. Crontab限制

    2. Crontab 命令

    3. Crontab 文件語法

    4. Crontab 實例

    5. Crontab 環境

    6. 禁止發送郵件

    7. 產生crontab 行為的Log 文件

    1.Crontab限制

    如果你的名字在文件/usr/lib/cron/cron.allow.中,那么你可以執行crontab,如果該文件不存在,但是你的名字不在文件/usr/lib/cron/cron.deny,你還是可以使用crontab 如果cron.deny存在并且為空,那么所有人都可以使用crontab,如果文件都不存在,那么只有root用戶可以使用crontaballow/deny文件中每行包含一個用戶名稱。

    2Crontab命令

    export EDITOR=vi 用于指定一個編輯器來打開crontab文件

    crontab -e  編輯crontab文件,如果不存在就創建一個

    crontab –l 顯示crontab文件內容

    crontab –r 移除crontab文件

    crontab –v 顯示你最后一個編輯crontab的時間(該選項只存在于少量系統中)

    3Crontab 文件

    Crontab 語法:

    Crontab文件有5個字段用于指定天,日期和時間,緊跟著是要運行的命令

    上面的值域中的*是指相應的字段所有的合法值。值字段中可以有一個*或者一個逗號分割的元素值的列表。每一個元素或者是上面顯示的范圍中的一個數字,或者是范圍中用-分割的兩個數字。

     
    *     *     *   *    *        command to be executed
    -     -     -   -    -
    |     |     |   |    |
    |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
    |     |     |   +------- month (1 - 12)
    |     |     +--------- day of        month (1 - 31)
    |     +----------- hour (0 - 23)
    +------------- min (0 - 59)
    

    要點

    A)每兩分鐘 /2 10分鐘 /10這樣的重復匹配模式在很多的操作系統不被支持。 如果你試圖使用,而crontab不接受,那么它可能不支持。

    B)標準中描述的天可以是以下的兩個域,月中的天和周中的天。如果條目中指定了這兩個,就顯得累積,意味著兩個條目都會得到執行。

    4Crontab實例

    像下面這樣Crontab中的文件行意思是在每天下午的6:30移除/home/someuser/tmp中的文件

    30     18     *     *     *         rm /home/someuser/tmp/*

    如下述列表中一樣改變參數的值可以使命令在不同的時間被調度

    min

    hour

    day/month

    month

    day/week

    Execution time

    30

    0

    1

    1,6,12

    *

    – 00:30 Hrs  on 1st of Jan, June & Dec.

     

    0

    20

    *

    10

    1-5

    –8.00 PM every weekday (Mon-Fri) only in Oct.

     

    0

    0

    1,10,15

    *

    *

    – midnight on 1st ,10th & 15th of month

     

    5,10

    0

    10

    *

    1

    – At 12.05,12.10 every Monday & on 10th of every month

    :

    注意:如果你不經意間輸入了沒有參數的crontab命令,不要試圖按Control-d退出,這樣會刪除文件中的所有條目,應該使用Control-c退出

    5. Crontab環境

    Cron使用shell(/usr/bin/sh)從用戶的home目錄中調用命令。

    Cron為每一個shell提供了一個缺省的環境,定義如下

    HOME=user’s-home-directory
    LOGNAME=user’s-login-id
    PATH=/usr/bin:/usr/sbin:.
    SHELL=/usr/bin/sh

    用戶想要執行他們自己的.profile必須顯式的在crontab 條目中,或者條目調用的相關腳本中做上面的設置

    6.禁止發送郵件

    默認情況下,cron jobs發送一封郵件給執行cronjob的用戶帳戶,如果不需要,在cronjob末尾的文件行鍵入以下命令

    >/dev/null 2>&1

    7. 產生相關的log文件

    收集cron執行的相關log并輸出到文件中

    30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log


    Setting up cron jobs in Unix and Solaris

    cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.

    This document covers following aspects of Unix cron jobs
    1. Crontab Restrictions
    2. Crontab Commands
    3. Crontab file – syntax
    4. Crontab Example
    5. Crontab Environment
    6. Disable Email
    7. Generate log file for crontab activity

    1. Crontab Restrictions
    You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
    crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
    If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.

    2. Crontab Commands

    export EDITOR=vi ;to specify a editor to open crontab file.

    crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
    crontab -l      Display your crontab file.
    crontab -r      Remove your crontab file.
    crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

    3. Crontab file
    Crontab syntax :
    A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

    *     *     *   *    *        command to be executed
    -     -     -   -    -
    |     |     |   |    |
    |     |     |   |    +----- day of week (0 - 6) (Sunday=0)
    |     |     |   +------- month (1 - 12)
    |     |     +--------- day of        month (1 - 31)
    |     +----------- hour (0 - 23)
    +------------- min (0 - 59)
    

    * in the value field above means all legal values as in braces for that column.
    The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
    Notes
    A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.

    B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .

    4. Crontab Example
    A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

    30     18     *     *     *         rm /home/someuser/tmp/*

    Changing the parameter values as below will cause this command to run at different time schedule below :

    min hour day/month month day/week Execution time
    30 0 1 1,6,12 * – 00:30 Hrs  on 1st of Jan, June & Dec.
    0 20 * 10 1-5 –8.00 PM every weekday (Mon-Fri) only in Oct.
    0 0 1,10,15 * * – midnight on 1st ,10th & 15th of month
    5,10 0 10 * 1 – At 12.05,12.10 every Monday & on 10th of every month
    :

    Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.

    5. Crontab Environment
    cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
    cron supplies a default environment for every shell, defining:
    HOME=user’s-home-directory
    LOGNAME=user’s-login-id
    PATH=/usr/bin:/usr/sbin:.
    SHELL=/usr/bin/sh

    Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

    6. Disable Email
    By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .

    >/dev/null 2>&1

    7. Generate log file
    To collect the cron execution execution log in a file :

    30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

     

    posted on 2012-06-12 21:49 Life is no respector of any genius. 閱讀(371) 評論(0)  編輯  收藏 所屬分類: Unix

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费A级毛片无码A∨中文字幕下载| 亚洲色大网站WWW永久网站| 男人j进女人p免费视频| 四虎成人免费影院网址| 亚洲五月丁香综合视频| 一二三四在线观看免费高清中文在线观看 | 亚洲人成电影网站色| 久久久久国色AV免费观看性色| 亚洲三级在线免费观看| 国产精品视频永久免费播放| 亚洲欧美第一成人网站7777| 国产小视频在线免费| 羞羞视频网站免费入口| 亚洲成?Ⅴ人在线观看无码| 91av免费在线视频| 亚洲AV无码一区二区二三区入口 | 亚洲av无码乱码国产精品| 午夜免费福利视频| 亚洲av无码不卡久久| 国产美女精品视频免费观看| 国产va免费精品| 激情内射亚洲一区二区三区| 久久精品网站免费观看| 人妻仑刮八A级毛片免费看| 国产亚洲精品美女久久久| 最近中文字幕国语免费完整| 久久久国产亚洲精品| 免费人成无码大片在线观看| 成人精品一区二区三区不卡免费看| 亚洲精品视频在线播放| 国产美女精品久久久久久久免费| 成人免费av一区二区三区| 亚洲无线一二三四区| 免费国产成人午夜私人影视 | 九九精品免费视频| 日亚毛片免费乱码不卡一区| 亚洲AV无码一区二区乱子伦 | 国产高清视频在线免费观看| 91在线免费观看| 亚洲精品无码久久久久APP| 亚洲色中文字幕无码AV|