Linux中國

在 CentOS/RHEL 系統上生成補丁合規報告的 Bash 腳本

如果你運行的是大型 Linux 環境,那麼你可能已經將 Red Hat 與 Satellite 集成了。如果是的話,你不必擔心補丁合規性報告,因為有一種方法可以從 Satellite 伺服器導出它。

但是,如果你運行的是沒有 Satellite 集成的小型 Red Hat 環境,或者它是 CentOS 系統,那麼此腳本將幫助你創建該報告。

補丁合規性報告通常每月創建一次或三個月一次,具體取決於公司的需求。根據你的需要添加 cronjob 來自動執行此功能。

bash 腳本 通常適合於少於 50 個系統運行,但沒有限制。

保持系統最新是 Linux 管理員的一項重要任務,它使你的計算機非常穩定和安全。

以下文章可以幫助你了解有關在紅帽 (RHEL) 和 CentOS 系統上安裝安全修補程序的更多詳細信息。

此教程中包含四個 shell 腳本,請選擇適合你的腳本。

方法 1:為 CentOS / RHEL 系統上的安全修補生成補丁合規性報告的 Bash 腳本

此腳本只會生成安全修補合規性報告。它會通過純文本發送郵件。

# vi /opt/scripts/small-scripts/sec-errata.sh

#!/bin/sh
/tmp/sec-up.txt
SUBJECT="Patching Reports on "date""
MESSAGE="/tmp/sec-up.txt"
TO="[email protected]"
echo "+---------------+-----------------------------+" >> $MESSAGE
echo "| Server_Name   |  Security Errata            |" >> $MESSAGE
echo "+---------------+-----------------------------+" >> $MESSAGE
for server in `more /opt/scripts/server.txt`
do
sec=`ssh $server yum updateinfo summary | grep 'Security' | grep -v 'Important|Moderate' | tail -1 | awk '{print $1}'`
echo "$server                $sec" >> $MESSAGE
done
echo "+---------------------------------------------+" >> $MESSAGE
mail -s "$SUBJECT" "$TO" < $MESSAGE

添加完上面的腳本後運行它。

# sh /opt/scripts/small-scripts/sec-errata.sh

你會看到下面的輸出。

# cat /tmp/sec-up.txt

+---------------+-------------------+
| Server_Name   |  Security Errata  |
+---------------+-------------------+
server1
server2
server3                21
server4
+-----------------------------------+

添加下面的 cronjob 來每個月得到一份補丁合規性報告。

# crontab -e

@monthly /bin/bash /opt/scripts/system-uptime-script-1.sh

方法 1a:為 CentOS / RHEL 系統上的安全修補生成補丁合規性報告的 Bash 腳本

腳本會為你生成安全修補合規性報告。它會通過 CSV 文件發送郵件。

# vi /opt/scripts/small-scripts/sec-errata-1.sh

#!/bin/sh
echo "Server Name, Security Errata" > /tmp/sec-up.csv
for server in `more /opt/scripts/server.txt`
do
sec=`ssh $server yum updateinfo summary | grep &apos;Security&apos; | grep -v &apos;Important|Moderate&apos; | tail -1 | awk &apos;{print $1}&apos;`
echo "$server,  $sec" >> /tmp/sec-up.csv
done
echo "Patching Report for `date +"%B %Y"`" | mailx -s "Patching Report on `date`" -a /tmp/sec-up.csv [email protected]
rm /tmp/sec-up.csv

添加完上面的腳本後運行它。

# sh /opt/scripts/small-scripts/sec-errata-1.sh

你會看到下面的輸出。

方法 2:為 CentOS / RHEL 系統上的安全修補、bugfix、增強生成補丁合規性報告的 Bash 腳本

腳本會為你生成安全修補、bugfix、增強的補丁合規性報告。它會通過純文本發送郵件。

# vi /opt/scripts/small-scripts/sec-errata-bugfix-enhancement.sh

#!/bin/sh
/tmp/sec-up.txt
SUBJECT="Patching Reports on "`date`""
MESSAGE="/tmp/sec-up.txt"
TO="[email protected]"
echo "+---------------+-------------------+--------+---------------------+" >> $MESSAGE
echo "| Server_Name   |  Security Errata  | Bugfix |  Enhancement        |" >> $MESSAGE
echo "+---------------+-------------------+--------+---------------------+" >> $MESSAGE
for server in `more /opt/scripts/server.txt`
do
sec=`ssh $server yum updateinfo summary | grep &apos;Security&apos; | grep -v &apos;Important|Moderate&apos; | tail -1 | awk &apos;{print $1}&apos;`
bug=`ssh $server yum updateinfo summary | grep &apos;Bugfix&apos; | tail -1 | awk &apos;{print $1}&apos;`
enhance=`ssh $server yum updateinfo summary | grep &apos;Enhancement&apos; | tail -1 | awk &apos;{print $1}&apos;`
echo "$server                $sec               $bug             $enhance" >> $MESSAGE
done
echo "+------------------------------------------------------------------+" >> $MESSAGE
mail -s "$SUBJECT" "$TO" < $MESSAGE

添加完上面的腳本後運行它。

# sh /opt/scripts/small-scripts/sec-errata-bugfix-enhancement.sh

你會看到下面的輸出。

# cat /tmp/sec-up.txt

+---------------+-------------------+--------+---------------------+
| Server_Name   |  Security Errata  | Bugfix |  Enhancement        |
+---------------+-------------------+--------+---------------------+
server01                                16
server02                  5             16
server03                  21           266             20
server04                                16
+------------------------------------------------------------------+

添加下面的 cronjob 來每三個月得到補丁合規性報告。該腳本計劃在一月、四月、七月、十月的 1 號運行。

# crontab -e

0 0 01 */3 * /bin/bash /opt/scripts/system-uptime-script-1.sh

方法 2a:為 CentOS / RHEL 系統上的安全修補、bugfix、增強生成補丁合規性報告的 Bash 腳本

腳本會為你生成安全修補、bugfix、增強的補丁合規性報告。它會通過 CSV 文件發送郵件。

# vi /opt/scripts/small-scripts/sec-errata-bugfix-enhancement-1.sh

#!/bin/sh
echo "Server Name, Security Errata,Bugfix,Enhancement" > /tmp/sec-up.csv
for server in `more /opt/scripts/server.txt`
do
sec=`ssh $server yum updateinfo summary | grep &apos;Security&apos; | grep -v &apos;Important|Moderate&apos; | tail -1 | awk &apos;{print $1}&apos;`
bug=`ssh $server yum updateinfo summary | grep &apos;Bugfix&apos; | tail -1 | awk &apos;{print $1}&apos;`
enhance=`ssh $server yum updateinfo summary | grep &apos;Enhancement&apos; | tail -1 | awk &apos;{print $1}&apos;`
echo "$server,$sec,$bug,$enhance" >> /tmp/sec-up.csv
done
echo "Patching Report for `date +"%B %Y"`" | mailx -s "Patching Report on `date`" -a /tmp/sec-up.csv [email protected]
rm /tmp/sec-up.csv

添加完上面的腳本後運行它。

# sh /opt/scripts/small-scripts/sec-errata-bugfix-enhancement-1.sh

你會看到下面的輸出。

via: https://www.2daygeek.com/bash-script-to-generate-patching-compliance-report-on-centos-rhel-systems/

作者:Magesh Maruthamuthu 選題:lujun9972 譯者:geekpi 校對:校對者ID

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的郵箱地址不會被公開。 必填項已用 * 標註

    這個站點使用 Akismet 來減少垃圾評論。了解你的評論數據如何被處理

    More in:Linux中國

    Linux中國

    捐贈 Let&apos;s Encrypt,共建安全的互聯網

    隨著 Mozilla、蘋果和谷歌對沃通和 StartCom 這兩家 CA 公司處罰落定,很多使用這兩家 CA 所簽發證書的網站紛紛尋求新的證書籤發商。有一個非盈利組織可以為大家提供了免費、可靠和安全的 SSL 證書服務,這就是 Let's Encrypt 項目。現在,它需要您的幫助
    Linux中國

    關於Linux防火牆iptables的面試問答

    Nishita Agarwal是Tecmint的用戶,她將分享關於她剛剛經歷的一家公司(印度的一家私人公司Pune)的面試經驗。在面試中她被問及許多不同的問題,但她是iptables方面的專家,因此她想分享這些關於iptables的問題和相應的答案給那些以後可能會進行相關面試的人。 所有的問題和相應的答案都基於Nishita Agarwal的記憶並經過了重寫。 嗨,朋友!我叫Nishita Agarwal。我已經取得了理學學士學位,我的專業集中在UNIX和它的變種(BSD,Linux)。它們一直深深的吸引著我。我在存儲方面有1年多的經驗。我正在尋求職業上的變化,並將供職於印度的P
    Linux中國

    Lets Encrypt 已被所有主流瀏覽器所信任

    旨在讓每個網站都能使用 HTTPS 加密的非贏利組織 Lets Encrypt 已經得了 IdenTrust的交叉簽名,這意味著其證書現在已經可以被所有主流的瀏覽器所信任。從這個裡程碑事件開始,訪問者訪問使用了Lets Encrypt 證書的網站不再需要特別配置就可以得到 HTTPS 安全保護了。 Lets Encrypt 的兩個中級證書 ...