LoginSignup
1
1

More than 5 years have passed since last update.

古いログを削除する(雑メモ)

Last updated at Posted at 2016-07-13

ローテートされた古いファイル名のログを列挙

大体で、↓こんなパターンのやつを消す。

  • *.[1234]
  • *.{gz,bz2}
  • *-20160712, *-2016-07-12
  • *.20160712, *.2016-07-12
  • *.old
list_old_logs.sh
find /var/log/ -type f |
grep -E ".*[\.-]([0-9]|old|20[0-9][0-9]-?[0-9][0-9]-?[0-9][0-9].*)(\.(gz|bz2))?$"

起動前のタイムスタンプのファイルを列挙

Snapshotイメージから起動した時とかに別インスタンスだった時代のログを消すとかそういうのに使える。

list_until_boot.sh
boottime=$(($(date +%s) - $(grep -oE ^[0-9]+ /proc/uptime)))
find /var/log/ -type f ! -newermt "@$boottime"

awslogs の監視先&ステートファイルを列挙

list_awslogs_files.sh
find /etc/awslogs/{awslogs.conf,config} /var/awslogs/etc/{awslogs.conf,config} -type f 2>/dev/null |
while read -r f; do
  grep -E '^\s*(state_)?file\s*=\s*/.*' "$f" | perl -pe's/.*file\s*=\s*//'
done
1
1
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
1
1