summaryrefslogtreecommitdiff
path: root/log-retention
diff options
context:
space:
mode:
authorBill <bill@billserver.senders.io>2021-04-15 18:35:31 -0400
committerBill <bill@billserver.senders.io>2021-04-15 18:35:31 -0400
commit9b5c18c0736fd30dc13050d8e99808e016aed757 (patch)
tree5147e71f0d8a5f6d27dc38ea9fc7fb628d658d87 /log-retention
parent26bdd486011e6f71c9366071c2223cf8282d9b6e (diff)
Create log retention script
Diffstat (limited to 'log-retention')
-rwxr-xr-xlog-retention/retention.sh14
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"