如何在CentOS/RHEL系统上生成补丁合规报告的Bash脚本

发布时间:2021-09-28 14:51:33 作者:柒染
来源:亿速云 阅读:100

本篇文章为大家展示了如何在CentOS/RHEL系统上生成补丁合规报告的Bash脚本,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

如果你运行的是大型 Linux 环境,那么你可能已经将 Red Hat 与 Satellite 集成了。如果是的话,你不必担心补丁合规性报告,因为有一种方法可以从 Satellite 服务器导出它。

但是,如果你运行的是没有 Satellite 集成的小型 Red Hat 环境,或者它是 CentOS 系统,那么此脚本将帮助你创建该报告。

补丁合规性报告通常每月创建一次或三个月一次,具体取决于公司的需求。根据你的需要添加 cronjob 来自动执行此功能。

此 bash 脚本 通常适合于少于 50 个系统运行,但没有限制。

保持系统最新是 Linux 管理员的一项重要任务,它使你的计算机非常稳定和安全。

此文章中包含四个 shell 脚本,请选择适合你的脚本。

方法 1:为 CentOS / RHEL 系统上的安全修补生成补丁合规性报告的 Bash 脚本

此脚本只会生成安全修补合规性报告。它会通过纯文本发送邮件。

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

添加完上面的脚本后运行它。

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

你会看到下面的输出。

# cat /tmp/sec-up.txt +---------------+-------------------+| Server_Name   |  Security Errata  |+---------------+-------------------+server1server2server3                21server4+-----------------------------------+

添加下面的 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/shecho "Server Name, Security Errata" > /tmp/sec-up.csvfor server in `more /opt/scripts/server.txt`dosec=`ssh $server yum updateinfo summary | grep 'Security' | grep -v 'Important|Moderate' | tail -1 | awk '{print $1}'`echo "$server,  $sec" >> /tmp/sec-up.csvdoneecho "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

你会看到下面的输出。

如何在CentOS/RHEL系统上生成补丁合规报告的Bash脚本

方法 2:为 CentOS / RHEL 系统上的安全修补、bugfix、增强生成补丁合规性报告的 Bash 脚本

脚本会为你生成安全修补、bugfix、增强的补丁合规性报告。它会通过纯文本发送邮件。

# vi /opt/scripts/small-scripts/sec-errata-bugfix-enhancement.sh #!/bin/sh/tmp/sec-up.txtSUBJECT="Patching Reports on "`date`""MESSAGE="/tmp/sec-up.txt"TO="[email protected]"echo "+---------------+-------------------+--------+---------------------+" >> $MESSAGEecho "| Server_Name   |  Security Errata  | Bugfix |  Enhancement        |" >> $MESSAGEecho "+---------------+-------------------+--------+---------------------+" >> $MESSAGEfor server in `more /opt/scripts/server.txt`dosec=`ssh $server yum updateinfo summary | grep 'Security' | grep -v 'Important|Moderate' | tail -1 | awk '{print $1}'`bug=`ssh $server yum updateinfo summary | grep 'Bugfix' | tail -1 | awk '{print $1}'`enhance=`ssh $server yum updateinfo summary | grep 'Enhancement' | tail -1 | awk '{print $1}'`echo "$server                $sec               $bug             $enhance" >> $MESSAGEdoneecho "+------------------------------------------------------------------+" >> $MESSAGEmail -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                                16server02                  5             16server03                  21           266             20server04                                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/shecho "Server Name, Security Errata,Bugfix,Enhancement" > /tmp/sec-up.csvfor server in `more /opt/scripts/server.txt`dosec=`ssh $server yum updateinfo summary | grep 'Security' | grep -v 'Important|Moderate' | tail -1 | awk '{print $1}'`bug=`ssh $server yum updateinfo summary | grep 'Bugfix' | tail -1 | awk '{print $1}'`enhance=`ssh $server yum updateinfo summary | grep 'Enhancement' | tail -1 | awk '{print $1}'`echo "$server,$sec,$bug,$enhance" >> /tmp/sec-up.csvdoneecho "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

你会看到下面的输出。

如何在CentOS/RHEL系统上生成补丁合规报告的Bash脚本

上述内容就是如何在CentOS/RHEL系统上生成补丁合规报告的Bash脚本,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. PHP7.4如何在CentOS环境中安装
  2. CentOS 6.0 启动时出现fstab错误怎么办

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

centos rhel bash脚本

上一篇:什么是CSS条件注释

下一篇:如何使用Ajax实时检测"用户名、邮箱等"是否已经存在

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》