0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

標準出力をLog Fileに書き出しつつLog Rotationさせたい

Last updated at Posted at 2015-05-28

何らかのToolの出力をLog fileに書き出したいけど、単一のLog fileへ書き出し続けると巨大になっちゃうので、出力を(手間を掛けずに)Log Rotationさせたい、と言うときの手順をチラ裏しておきます。

結論

使い方

毎秒ごとに1行づつ標準出力にLogを吐き出すScriptを10分動かして、3分毎にRotateさせつつLogをfileに保存する、というCase studyを考えてみる。Shell scriptの中身は以下の通り (600回echoして1秒待つを繰り返す)

test.sh
for i in `seq 1 600`
do
  echo "$i times loop"
  sleep 1s
done

これをcronologを使いつつ、Log出力する場合

./test.sh | /usr/bin/cronolog --period=3minutes log-%Y-%m-%d-%H-%M.out

10分待つと、以下の様なfile名のlog fileが出来るはず

log-2015-05-28-03-00.out
log-2015-05-28-03-03.out
log-2015-05-28-03-06.out
log-2015-05-28-03-09.out

その他

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?