*********************************
anonymize_log_ip
*********************************
Script for anonymizing IPs in logfiles
Usage: anonymize_log_ip.sh -f {logfile} -age {days} (-e {exclude})
arguments:
-f --file {logfile}
(default: /var/log/apache2/*.log*)
-age {days} to keep IPs in logfiles
(default: 7)
Note: set to 0 to disable age check
optional arguments:
-e {string} exclude one or more strings from search
Note: use -e before each string
-h --help shows this help message
-V --version prints version and release info
--debug verbose debug infos on console
***********************************************************************
Thank you for using this script!
For more infos on our services please visit www.admin-box.de
Changelog
v1.0 2018-06-13 initial release
Installation/Voraussetzungen
Abhängigkeiten
gzip gunzip bc grep find sed
Dokumentation
Arbeitsweise
Das Script sucht mit find die angegebenen logfiles, und checkt ihr Alter mit stat -c %Y
Falls die Logfiles komprimiert sind, entpackt das Script sie mit gunzip
Mittels sed werden alle IP-adressen mit xxx.xxx.xxx ersetzt.
Falls das Logfile komprimiert war, wird es nachher wieder mit gzip komprimiert.
Dieses Script beeinflusst die Funktionalität von logrotate nicht, und wird zusätzlich dazu eingesetzt, z.B. als
cronjob.
Scriptausgabe wird gelogt nach LOG="/tmp/${PROGNAME}.log"
Fehler werden gelogt nach ERR_LOG="/tmp/${PROGNAME}.error.log" mit Timestamp
timestamp_log=$(date "+%F %T") (kann im Quellcode angepasst werden)
Kommandozeilenparameter
-f {filename}
logfile name (default: /var/log/apache2/*.log* ) Dieser Parameter wird an find übergeben, und
benutzt dieselbe Syntax für Wildcards bzw regex. Siehe man find.
--age {number}
Alter in Tagen, nachdem die Logfiles anonymisiert werden. (default: 7) Wert 0 benutzen, um den age-Check zu deaktivieren
und alle Logfiles zu anonymisieren.
-e {exclude_string}
Einen bestimmten String (logfile name, folder, etc) von der Suche ausschließen. Auche mehrere -e Parameter
möglich.
Um DSGVO-Anforderungen zu erfüllen, hat uns ein Kunde gebeten dieses Script zu entwickeln.
Man hätte es alternativ auch in der prerotate-Anweisung im logrotate lösen können, jedoch
wollte der Kunde die rotation weiterhin auf daily belassen, aber erst nach 7 Tagen die IPs anonymisieren.
Download
#############################
### Copyright and License ###
#############################
#
# Copyright (C) 2018 Anton Daudrich
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see http://www.gnu.org/licenses/.
#
#############################