From 65a60aea1863209f49994542baeab1a88cc60211 Mon Sep 17 00:00:00 2001 From: "painpain@minty" Date: Tue, 17 Feb 2026 20:57:36 +0100 Subject: [PATCH] archive_connections --- usr/bin/archive_connections | 27 +++++++++++++++++++++++++++ usr/bin/v | 3 +++ 2 files changed, 30 insertions(+) create mode 100755 usr/bin/archive_connections create mode 100755 usr/bin/v diff --git a/usr/bin/archive_connections b/usr/bin/archive_connections new file mode 100755 index 0000000..dd9dda3 --- /dev/null +++ b/usr/bin/archive_connections @@ -0,0 +1,27 @@ +#!/bin/bash + +SRC=/var/log/connections/lasts.tcpd +DST=/var/log/connections/archive +DATE=$(date "+%y%m%d-%H%M") +MAXSIZE=$((1024*1024*1024)) # 1 Go + +mkdir -p "$DST" + +# 1️⃣ Archivage IP en .txt +find "$SRC" -name "*.log" -mmin -30 \ + | xargs grepip \ + > "$DST/connections-$DATE.txt" + +# 2️⃣ Archiver les logs dans un tar.gz +ARCHIVE="$DST/logs-$DATE.tar.gz" +find "$SRC" -name "*.log" -print0 | tar --null -czf "$ARCHIVE" --remove-files -T - + +# 3️⃣ Vérifier la taille totale des archives et supprimer les plus anciennes si >1 Go +total_size=$(du -cb "$DST"/*.tar.gz 2>/dev/null | tail -1 | awk '{print $1}') + +while [ "$total_size" -ge $MAXSIZE ]; do + oldest=$(ls -1t "$DST"/*.tar.gz | tail -1) + [ -f "$oldest" ] && rm -f "$oldest" + total_size=$(du -cb "$DST"/*.tar.gz 2>/dev/null | tail -1 | awk '{print $1}') +done + diff --git a/usr/bin/v b/usr/bin/v new file mode 100755 index 0000000..6e38db7 --- /dev/null +++ b/usr/bin/v @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +nvim $@