[PATCH 4/4] contrib: Add a script to clean up in regular intervals

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Daniel Willmann daniel at totalueberwachung.de
Sun Jul 17 15:48:20 UTC 2011


This script should be run from cron. It compresses and deletes older
files.
---
 Makefile.am         |    2 +-
 configure.ac        |    1 +
 contrib/Makefile.am |    1 +
 contrib/clean_old   |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletions(-)
 create mode 100644 contrib/Makefile.am
 create mode 100755 contrib/clean_old

diff --git a/Makefile.am b/Makefile.am
index b9a4331..7c9c65b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
 
-SUBDIRS = include src
+SUBDIRS = include src contrib
 
 BUILT_SOURCES = $(top_srcdir)/.version
 EXTRA_DIST = git-version-gen
diff --git a/configure.ac b/configure.ac
index 9977ef6..2f4de9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,4 +57,5 @@ AC_OUTPUT(
     include/Makefile
     include/osmo-pcap/Makefile
     src/Makefile
+    contrib/Makefile
     Makefile)
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 0000000..b392196
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1 @@
+dist_pkgdata_DATA = clean_old
diff --git a/contrib/clean_old b/contrib/clean_old
new file mode 100755
index 0000000..3294c45
--- /dev/null
+++ b/contrib/clean_old
@@ -0,0 +1,46 @@
+#! /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
+
+CLIENTS=$(find $BASEPATH -name "trace-*" |sed -e "s/.*trace-\([^-]\+\).*/\1/" |sort |uniq)
+
+do_cleanup()
+{
+	i=1
+	for log in $(find $BASEPATH -name "trace-$1*" |sort); 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
+}
+
+for client in $CLIENTS; do
+	[ $VERBOSE -eq 1 ] && echo "Cleaning logs for $client"
+	do_cleanup $client
+done
-- 
1.7.5.3





More information about the OpenBSC mailing list