Skip to content

Instantly share code, notes, and snippets.

@tschifftner
Last active March 30, 2021 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschifftner/ac09d17e8878ec89d930387050b4224b to your computer and use it in GitHub Desktop.
Save tschifftner/ac09d17e8878ec89d930387050b4224b to your computer and use it in GitHub Desktop.
Clean fail2ban database from older entry - use script with cronjob!
#!/usr/bin/env bash
# Tobias Schifftner, @tschiffnter
#
# Usage:
# bash fail2ban-cleanup.php <fail2ban.sqlite3>
FILE=${1:-"/var/lib/fail2ban/fail2ban.sqlite3"}
[ -f "$FILE" ] || { echo "$FILE not found"; exit 1; }
function sql() {
$(which sqlite3) "$FILE" "$@"
}
sql "DELETE FROM bans WHERE timeofban < strftime('%s', 'now', '-7 days');"
sql "VACUUM;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment