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 的两个中级证书 ...