Fail2Ban - Daily Yesterday summary

T

his tutorial works for CentOS only. For your specific OS tutorial use the tags or serach function in the sidebar area.

 

Today we take care of a script that sends an e-mail daily with a summary of banned hosts previous day by Fail2ban (useful along with Logwatch)

Of course if you don't you should have outgoing mail service configured already.

You may check:
Set-up sending mail via gmail account

or

Setup Postfix + Dovecot + Roundcube (almost a mailserver)
 

So, we create a file (script) called fail2ban-info.sh:

[root@server][~]
$ cd /root/

[root@server][~]
$ touch fail2ban-info.sh

[root@server][~]
$ chmod 0755 fail2ban-info.sh

[root@server][~]
$ chmod x fail2ban-info.sh

[root@server][~]
$ nano fail2ban-info.sh
 

Copy and paste below source code, change admin@example.com to your mail.

Test it by typing:

$ ./fail2ban-info.sh

Check e-mail.

If you get:

 
[root@server][~]
$ ./fail2ban-info.sh
Null message body; hope that's ok
 

means that no hosts were banned yesterday and empty mail is sent.

You can add this script to Cron task to perform daily

To do this simply move whole script to Cron daily directory:

$ mv fail2ban-info.sh /etc/cron.daily/