ログ監視

  • cron の設定方法を記す.
  • cron.local によるログ監視システムを導入する. これは以下のメールを管理者に送るシステムである

    crontab の編集

    crontab は以下のように記入する.
     # emacs /etc/crontab 
    
    ----------
    #!/bin/sh
    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/mail
    
    MAILTO=epwww@ep.sci.hokudai.ac.jp
    
    
    # m h dom mon dow user  command
    # 0-59/2 * * * * /bin/date > /home/wataken/cron_test 2>&1
    #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 )
    

    cron.local の導入方法

    作業

    1. ソースをcron.local.tar.bz2から入手する.
      # wget http://www.ep.sci.hokudai.ac.jp/~epwww/dvlop/script/cron.local.tar.bz2 -P /etc/
      (-Pは保存先の指定をするオプション)
      
    2. 展開する
      # cd /etc/ && bzcat cron.local.tar.bz2 | tar xvf -
      
    3. 展開したファイルに実行権限がない場合には付ける
      # ls -l /etc/cron.local/daily/*
      # ls -l /etc/cron.local/weekly/*
      # chmod 755 cron.local/daily/* cron.local/weekly/*
      
    4. crontab に起動指示?を書きこむ
      # vim /etc/crontab
      
      --------
      #!/bin/sh
      # /etc/crontab: system-wide crontab
      # Unlike any other crontab you don't have to run the `crontab'
      # command to install the new version when you edit this file
      # and files in /etc/cron.d. These files also have username fields,
      # that none of the other crontabs do.
      
      SHELL=/bin/sh
      PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/mail
      
      MAILTO=epwww@ep.sci.hokudai.ac.jp
      
      :
      :
      :
      
      25 6  * * *   root    cd / && run-parts --report /etc/cron.local/daily | mail -s "`hostname -f` daily
      run outputs" epwww@ep.sci.hokudai.ac.jp
      47 6  * * 7   root    cd / && run-parts --report /etc/cron.local/weekly | mail -s "`hostname -f` weekl
      y run outputs" epwww@ep.sci.hokudai.ac.jp
      
      

      この設定だと毎朝の6:25にdailyが日曜日の6:47にweeklyが届く

    5. crontab をリスタートする
    6. # /etc/init.d/cron restart
      

    最終更新日: 2014/05/21 渡辺 健介 Copyright © 2013 epcore