Fail2Banの自動インストールと設定用のスクリプトを書くには、/etc/fail2ban/jail.localを変更する方法が必要です。私の問題は、ファイルの特定のセクションに行を追加する必要があるということですが、領域内にパターンenabled = true
が存在しない場合に限ります。 enable = true
を書くべきではない他の領域があります。sed/awkは2つのマッチの間に行を挿入しますが、他のパターンがない場合のみ
次SEDSが正常に動作しますが、enabled = true
がすでに存在しているかどうかをチェックしません:
sed '/\[apache-auth\]/{x;s/.*/./;x};/port/{x;/^.$/{x;s/^/enabled = true\n/;x};s/^/./;x}' -i /etc/fail2ban/jail.local
sed '/\[apache-badbots\]/{x;s/.*/./;x};/port/{x;/^.$/{x;s/^/enabled = true\n/;x};s/^/./;x}' -i /etc/fail2ban/jail.local
sed '/\[apache-noscript\]/{x;s/.*/./;x};/port/{x;/^.$/{x;s/^/enabled = true\n/;x};s/^/./;x}' -i /etc/fail2ban/jail.local
sed '/^\[sshd\]/{x;s/.*/./;x};/port/{x;/^.$/{x;s/^/enabled = true\n/;x};s/^/./;x}' -i /etc/fail2ban/jail.local
要求された情報
元のファイル
[sshd]
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
[apache-auth]
port = http,https
logpath = %(apache_error_log)s
[apache-badbots]
# Ban hosts which agent identifies spammer robots crawling the web
# for email addresses. The mail outputs are buffered.
port = http,https
logpath = %(apache_access_log)s
bantime = 172800
maxretry = 1
[apache-noscript]
port = http,https
logpath = %(apache_error_log)s
を追加するアップデート予想される出力
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
#
# HTTP servers
#
[apache-auth]
enabled = true
port = http,https
logpath = %(apache_error_log)s
[apache-badbots]
# Ban hosts which agent identifies spammer robots crawling the web
# for email addresses. The mail outputs are buffered.
enabled = true
port = http,https
logpath = %(apache_access_log)s
bantime = 172800
maxretry = 1
[apache-noscript]
enabled = true
port = http,https
logpath = %(apache_error_log)s
英語ので、私のスペルミスを判断しないでください、私の母国ではありません。これがこの質問の正しいサイトであるかどうかもわかりません。
入力ファイルと出力ファイルを貼り付けてください。 –
@VIPINKUMAR入力ファイルと目的の出力を追加しました –
サンプルをダウンロードした場合は、50行でなく15行と言います。それがあれば何とかなりますお客様の要件を理解する時間が大幅に短縮されます。いずれの方向にもスクロールバーが必要なときは、サンプルが大きすぎますので、もう一度[mcve](注** **最小**)を作成してみてください。 –