ローテートされた古いファイル名のログを列挙
大体で、↓こんなパターンのやつを消す。
- *.[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