首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Fail2Ban配置中使用bash脚本

在Fail2Ban配置中使用bash脚本
EN

Stack Overflow用户
提问于 2018-03-14 21:36:49
回答 1查看 1.1K关注 0票数 2

我想在Fail2Ban的邮件中调用一个bash脚本。bash脚本调用rest api通过fail2ban获取被阻止的ip地址的用户名。

代码语言:javascript
复制
# Fail2Ban configuration file
#
# Author: *
#
#

[INCLUDES]

before = sendmail-common.conf

[Definition]

# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    See jail.conf(5) man page
# Values:  CMD
#
actionban = printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from `uname -n`
            Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
            From: <sendername> <<sender>>
            To: <dest>\n
            The following IP <ip> has just been banned by Fail2Ban after <failures> attempts against the acceptance environment of <name> on server.\n
            One or the following users could be the victim: \n 
            `/etc/fail2ban/restapi/getHttpSessions.sh | grep <ip>` \n | /usr/sbin/sendmail -f <sender> <dest>

[Init]

但是,我在fail2ban日志中收到了没有发送电子邮件的错误

代码语言:javascript
复制
`/bin/sh /etc/fail2ban/scripts/getHttpSessions.sh | grep` 10.100.00.00 \n |/usr/sbin/sendmail -f fail2ban test@test.com -- returned 1

有没有办法在fail2ban配置文件中使用bash脚本在bash创建的概述中查找IP地址?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-03-15 16:49:08

我把它修好了。可能是语法中的一些问题。工作代码:

代码语言:javascript
复制
# Fail2Ban configuration file
#
# Author: Danny van den Berg
#
#

[INCLUDES]

before = sendmail-common.conf

[Definition]

# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    See jail.conf(5) man page
# Values:  CMD
#
actionban = printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from `uname -n`
            Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
            From: <sendername> <<sender>>
            To: <dest>\n
            The following IP <ip> has just been banned by Fail2Ban after <failures> attempts against the production environment of <name> on server.\n
            More information about the user:\n 
            [IP            | KEY] \n
            `/usr/bin/gethttpsessions | grep <ip> `\n\n" | /usr/sbin/sendmail -f <sender> <dest>

[Init]

# Default name of the chain
#
name = default
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49279203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档