diff options
-rwxr-xr-x | log-retention/retention.sh | 14 |
1 files changed, 14 insertions, 0 deletions
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" |