Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@artfulrobot

This comment has been minimized.

Show comment
Hide comment
@artfulrobot

artfulrobot Oct 19, 2014

Thanks! can't believe there isn't a fail2ban-client status --all command!

Thanks! can't believe there isn't a fail2ban-client status --all command!

@mattgorecki

This comment has been minimized.

Show comment
Hide comment
@mattgorecki

mattgorecki Dec 19, 2016

Excellent! It was -e for me on Centos 6.

Excellent! It was -e for me on Centos 6.

@xrobin

This comment has been minimized.

Show comment
Hide comment
@xrobin

xrobin Jan 19, 2017

Great!
On a SLES box I had to use lowercase -e as well, and escape the + signs in the regex

JAILS=`fail2ban-client status | grep "Jail list" | sed -e 's/^[^:]\+:[ \t]\+//' | sed 's/,//g'`

xrobin commented Jan 19, 2017

Great!
On a SLES box I had to use lowercase -e as well, and escape the + signs in the regex

JAILS=`fail2ban-client status | grep "Jail list" | sed -e 's/^[^:]\+:[ \t]\+//' | sed 's/,//g'`
@caic

This comment has been minimized.

Show comment
Hide comment
@caic

caic Jan 31, 2017

Thank you! It works on Ubuntu 16.04.

caic commented Jan 31, 2017

Thank you! It works on Ubuntu 16.04.

@acosonic

This comment has been minimized.

Show comment
Hide comment
@acosonic

acosonic Feb 22, 2017

Thank you! Also confirming works on Ubuntu 16.04

Thank you! Also confirming works on Ubuntu 16.04

@maravedi

This comment has been minimized.

Show comment
Hide comment
@maravedi

maravedi Mar 8, 2017

This is perfect 👍

maravedi commented Mar 8, 2017

This is perfect 👍

@ahmadawais

This comment has been minimized.

Show comment
Hide comment
@shlublu

This comment has been minimized.

Show comment
Hide comment
@shlublu

shlublu Jul 6, 2017

It has been said already, but many thanks (Ubuntu 16.04)! :)

shlublu commented Jul 6, 2017

It has been said already, but many thanks (Ubuntu 16.04)! :)

@kofran

This comment has been minimized.

Show comment
Hide comment
@kofran

kofran Aug 16, 2017

Thanks so much

kofran commented Aug 16, 2017

Thanks so much

@welrbraga

This comment has been minimized.

Show comment
Hide comment
@welrbraga

welrbraga Dec 7, 2017

Why make it easy if you can do hard? :-)

fail2ban-client status|awk -F: '/Jail list:/ { split($2,jail,",") ; for (i in jail) { gsub(/[\t ]/,"",jail[i]); system("fail2ban-client status "jail[i]); }; }'

Why make it easy if you can do hard? :-)

fail2ban-client status|awk -F: '/Jail list:/ { split($2,jail,",") ; for (i in jail) { gsub(/[\t ]/,"",jail[i]); system("fail2ban-client status "jail[i]); }; }'

@joergludwig

This comment has been minimized.

Show comment
Hide comment
@joergludwig

joergludwig Dec 20, 2017

Shorter version:
fail2ban-client status | sed -n 's/,//g;s/.*Jail list://p' | xargs -n1 fail2ban-client status

Shorter version:
fail2ban-client status | sed -n 's/,//g;s/.*Jail list://p' | xargs -n1 fail2ban-client status

@Fieel

This comment has been minimized.

Show comment
Hide comment
@Fieel

Fieel Jan 17, 2018

Nice! Will use this script in my server, ty again <3

Fieel commented Jan 17, 2018

Nice! Will use this script in my server, ty again <3

@VA2PE

This comment has been minimized.

Show comment
Hide comment
@VA2PE

VA2PE Feb 9, 2018

Thanks, works well on CentOS 7.

VA2PE commented Feb 9, 2018

Thanks, works well on CentOS 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment