diff options
author | Daniel Willmann <daniel@totalueberwachung.de> | 2011-07-19 11:58:15 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-07-19 17:56:13 +0200 |
commit | 5d62ed0904204b9064699475cd55f6832d46ad67 (patch) | |
tree | 7964e14f73ce7b7b63079cede8e194f7bd79ec21 /contrib/osmo_pcap_clean_old | |
parent | b000368ad6609c8755a8da7a0dbe89a4be002666 (diff) |
contrib: Add a script to clean up in regular intervals
This script should be run from cron. It compresses and deletes older
files.
Diffstat (limited to 'contrib/osmo_pcap_clean_old')
-rwxr-xr-x | contrib/osmo_pcap_clean_old | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/contrib/osmo_pcap_clean_old b/contrib/osmo_pcap_clean_old new file mode 100755 index 0000000..d24a94b --- /dev/null +++ b/contrib/osmo_pcap_clean_old @@ -0,0 +1,47 @@ +#! /bin/sh + +# Script designed to clean up (zip/delete) old files +# Adjust the variables below and then copy/symlink this script +# to /etc/cron/cron.{hourly,daily} + +# We want to keep the filenames dated and that confuses logrotate, +# hence this script. + +# Number of pcap files per client +NUMFILES=8 +ZIPAFTER=3 +VERBOSE=0 + +# Path where the logfiles reside in +BASEPATH="/var/lib/osmo-pcap/" + +# Find the client names present in basepath +# Check how many files there are for each client +# Delete files in excess of NUMFILES + +cd "$BASEPATH" + + +do_cleanup() +{ + i=1 + find . -name "trace-$1*" |sort | while read LOG; do + if [ $i -gt $NUMFILES ]; then + [ $VERBOSE -eq 1 ] && echo "Deleting file \"$LOG\"" + rm -f "$LOG" + elif [ $i -gt $ZIPAFTER ]; then + if [ "${LOG##*.}" != "gz" ]; then + [ $VERBOSE -eq 1 ] && echo "Compressing file \"$LOG\"" + gzip "$LOG" + fi + else + [ $VERBOSE -eq 1 ] && echo "Noop for file \"$LOG\"" + fi + i=$(($i+1)) + done +} + +find . -name "trace-*" |sed -e "s/.*trace-\([^-]\+\).*/\1/" |sort |uniq | while read CLIENT; do + [ $VERBOSE -eq 1 ] && echo "Cleaning logs for $CLIENT" + do_cleanup "$CLIENT" +done |