Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate a Bash script for patch compliance reports on CentOS/RHEL systems

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to generate a Bash script for patch compliance reports on CentOS/RHEL systems. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

If you are running a large Linux environment, you may have integrated Red Hat with Satellite. If so, you don't have to worry about the patch compliance report, because there is a way to export it from the Satellite server.

However, if you are running a small Red Hat environment without Satellite integration, or if it is a CentOS system, then this script will help you create the report.

Patch compliance reports are usually created once a month or once every three months, depending on the needs of the company. Add cronjob to perform this function automatically according to your needs.

This bash script is usually suitable for running on less than 50 systems, but there is no limit.

Keeping your system up to date is an important task for Linux administrators. It makes your computer very stable and secure.

This article contains four shell scripts, please choose the one that suits you.

Method 1: Bash script that generates patch compliance reports for security patches on CentOS / RHEL systems

This script only generates security patch compliance reports. It sends messages in plain text.

# 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'{server $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'{server1} '``echo "$server, $sec" > > / tmp/sec-up.csvdoneecho "Patching Report for `date +"% Y "`" | mailx-s "Patching Report on `date`"-a / tmp/sec-up.csv [email protected] rm / tmp/sec-up.csv

Run the above script after you have added it.

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

You will see the following output.

Method 2: Bash script that generates patch compliance reports for security patches, bugfix, and enhancements on CentOS / RHEL systems

The script will generate security patch, bugfix, and enhanced patch compliance reports for you. It sends messages in plain text.

# 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} '`enhance= `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

Run the above script after you have added it.

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

You will see the following output.

The above is how to generate a Bash script for patch compliance reports on CentOS/RHEL systems. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report