Browse - Programming Tips - Fail2ban: list full status

Date: 2018jun20
OS: Linux
Language: perl

Q.  Fail2ban: list full status

A.  `fail2ban-client status` doesn't list everything so I made this script.
It first shows `fail2ban-client status` and reads the names of the jails
and does `fail2ban-client status <jail>` for each jail.

#!/usr/bin/perl use strict; sub main() { my($h, $line, $jails, @jails, $jail); open($h, 'fail2ban-client status|'); while ($line = <$h>) { chomp($line); print "$line\n"; if ($line =~ m/Jail list:\s*(.+)/i) { $jails = $1; @jails = split(/\s*,\s*/, $jails); } } close($h); print "\n"; for $jail (@jails) { open($h, "fail2ban-client status $jail|"); while ($line = <$h>) { chomp($line); print "$line\n"; } close($h); print "\n"; } } main();