From 9b5c18c0736fd30dc13050d8e99808e016aed757 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 15 Apr 2021 18:35:31 -0400 Subject: Create log retention script --- log-retention/retention.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 log-retention/retention.sh (limited to 'log-retention') diff --git a/log-retention/retention.sh b/log-retention/retention.sh new file mode 100755 index 0000000..48a2758 --- /dev/null +++ b/log-retention/retention.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +LOGFILE=$1 + +mindate=$(head -n1 $LOGFILE | cut -f1 | cut -d'T' -f1) +maxdate=$(date --date="-6 days" -u -Id) + +echo "Deleting log lines from ${mindate} to ${maxdate}" + +sed -i -E "/${mindate}/,/${maxdate}/d" $LOGFILE + +echo "Cleared logs" -- cgit v1.2.3-54-g00ecf