naobe @ ウィキ

cron

最終更新:

Bot(ページ名リンク)

- view
管理者のみ編集可
Linuxへもどる

/etc/crontab

  • rootが実行するcronを規定する
  • 空行、先頭のスペース、タブは無視される。
  • 先頭が#の行は無視される(コメント)
  • 動作行は、環境変数の設定、コマンド
  • コマンド部は以下
    • 曜日 0と7は日曜日
    • ユーザ
    • コマンド
  • 日時は、以下の形式を指定できる。
    • 範囲指定 8-11
    • リスト コンマ","で区切る
    • 間隔 */2 2時間おき。5-10/2 5時から10の間で2時間おき。

【設定例】
 # 環境変数設定
 SHELL=/bin/[[bash]]
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=root
 HOME=/
 
 # run-parts(コマンド)
 01 * * * * root run-parts /etc/cron.hourly
 # 毎日 4時2分
 02 4 * * * root run-parts /etc/cron.daily
 22 4 * * 0 root run-parts /etc/cron.weekly
 42 4 1 * * root run-parts /etc/cron.monthly

/etc/cron.daily

run-partsが/etc/cron.daily下のコマンドを名前の昇順に実行する

/etc/cron.daily/logrotate

/etc/logrotate.confを引数にlogrotateを実行する
 #!/bin/sh
 
 /usr/sbin/logrotate /etc/logrotate.conf
 EXITVALUE=$?
 if [ $EXITVALUE != 0 ]; then
     /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
 fi
 exit 0

/etc/logrotate.conf


 # see "man logrotate" for details
 # rotate log files weekly
 #
 # グローバルオプション
 # 週に1回(毎日曜日)
 weekly
 
 # keep 4 weeks worth of backlogs
 #
 # グローバルオプション
 # ファイルを4個まで作成する
 rotate 4
 
 # create new (empty) log files after rotating old ones
 #
 # グローバルオプション
 create
 
 # uncomment this if you want your log files compressed
 #compress
 
 # RPM packages drop log rotation information into this directory
 #
 # /etc/logrotate.d下のファイルをインライン展開する
 include /etc/logrotate.d
 
 # no packages own wtmp -- we'll rotate them here
 /var/log/wtmp {
     monthly
     minsize 1M
     create 0664 root utmp
     rotate 1
 }
 
 # system-specific logs may be also be configured here.

/etc/logrotate.d/syslog

sharedscripts:複数のファイルに対して、まとめて1回処理する。(postrotate, prerotateに対する修飾)

 /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
     sharedscripts
     postrotate
         /bin/kill -HUP `cat /var/run/[[syslog]]d.pid 2> /dev/null` 2> /dev/null || true
         /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
     endscript
 }
人気記事ランキング
ウィキ募集バナー