Simplify fail2ban output (#2703)

This commit is contained in:
Casper 2022-07-29 18:14:35 +02:00 committed by GitHub
parent 57aeb6db2a
commit 11f8cc7ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,6 @@ fail2ban-client ping &>/dev/null || _exit_with_error "Fail2ban not running"
unset JAILS
declare -a JAILS
IP_REGEXP='((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
for LIST in $(fail2ban-client status | grep "Jail list" | cut -f2- | sed 's/,/ /g')
do
@ -22,13 +21,11 @@ then
for JAIL in "${JAILS[@]}"
do
BANNED_IPS=$(fail2ban-client status "${JAIL}" \
| grep 'Banned IP list' \
| grep -oE "${IP_REGEXP}")
BANNED_IPS=$(fail2ban-client status "${JAIL}" | grep -oP '(?<=Banned IP list:\s).+')
if [[ -n ${BANNED_IPS} ]]
then
echo "Banned in ${JAIL}: ${BANNED_IPS//$'\n'/, }"
echo "Banned in ${JAIL}: ${BANNED_IPS}"
IPS_BANNED=1
fi
done