Last active
July 3, 2020 18:53
-
-
Save yolabingo/ef4a41853b46503bb2e6537d1129fb46 to your computer and use it in GitHub Desktop.
purge old fail2ban bans from sqlite db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# prune sqlite db file for fail2ban v 0.9.x | |
# run me from cron to keep sqlite db a sane size | |
# fail2ban doesn't purge old entries from sqlite db, so it grows until things break | |
# https://gist.github.com/yolabingo/ef4a41853b46503bb2e6537d1129fb46 | |
dbfile=$(fail2ban-client get dbfile | grep "\`-" | awk '{print $2}') | |
dbpurgeage=$(fail2ban-client get dbpurgeage | grep "\`-" | awk '{print $2}' | sed 's/seconds.*//') | |
python << EOF | |
import sys, logging | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
from fail2ban.server.database import Fail2BanDb | |
db = Fail2BanDb(${dbfile}, ${dbpurgeage}) | |
db.purge()" | |
EOF | |
sqlite3 $dbfile 'VACUUM;' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment