Redhat7 complete patch information

     Formerly indirect also learned some of the Linux-based, long-term without a lot of knowledge points have been forgotten. Now ready on the operation and maintenance of this road even further, so Linux discipline, language under-depth study recently started.

     Recently I communicate with the company, fortunately granted that we can do the project together with Daniel, to promote our progress. The first task is to get Redhat7 complete patch information to summarize statistics. Project requirements are as follows:

From https://access.redhat.com/errata/#/?q=&p=1&sort=portal_publication_date%20desc&rows=100&portal_advisory_type=Security%20Advisory&portal_product=Red%20Hat%20Enterprise%20Linux&portal_product_variant=Red%20Hat%20Enterprise%20Linux%20Server&portal_product_version= 7 & portal_architecture = x86_64  information acquired link open patch information is stored in the following manner

image.png

    Would like to complete this project There are many ways, one of which is one of the links and then open the information we obtained one by one to fill in the table above, but too time-consuming, and have lost the original purpose of our project, so we will certainly be With the knowledge we have learned to simplify this issue, make things easier laborious cheerful. Here are my ideas and achievements of the past few days, of course, spend so much time, also told me just a preliminary study of the system related to Linux, no way knowledge is weak it can only learn a knowledge with a knowledge point!

     First, the next we detailed analysis of this issue:

          1, would like to complete this form in fact, we only need to find RHSA number, CVE, related links, security type, and can be described

          2, how to obtain the data in this link, we need to get the source code for this link

          3, that by opening the source code RHSA number two data links can be obtained directly from the page's source code, CVE, security type, and a description of the need to open links from relevant captured in the content available.

     Second, the course of the project (knowledge is limited, only in the case of the existing stock of knowledge of thinking)

          1, how to obtain the source code Redhat7 link

           HTML source code files found by #curl Redhat7 link >> linux.html then obtained in the absence of such a few keywords we need in practice Linux system, so I can only through the web links will open Redhat7 save renamed, and then I will open this redhat.html page locally as redhat.html this file to the desktop, and then press F12 to save the source code available test.html file to another file, this time we found test.html file there is a keyword in the address information RHSA we need a number, and related links. (In fact, this test.html file does not contain all information about all RHSA numbers, because this information through the Access to over nine hundred pieces, is open tabs, just save it as a way in which we set to open just one of 100 Article number information, of course, this does not affect our study this problem, we only need to repeat the operation several times just fine on the basis of the complete data on page 100)

         2, by means test.html we upload the file on the local desktop to the Linux operating system we use, and here I use the CentOS6.8 system. After we uploaded the file to manipulate to get what we want RHSA numbers and links this data

        Get RHSA number of command #grep "RHSA" test.html | grep --color "href" | cut -d = -f7 | cut -d ' "' -f2 | cut -d '/' -f5

        For the link command #grep "RHSA" test.html | grep --color "href" | cut -d = -f7 | cut -d ' "' -f2> test1.txt This command is the result of our acquired save 100 test1.txt link to this file

        3, after obtaining the 100 links, we will need to go through these links eleven links to get CVE, security type, and the corresponding description, for example:

Get command from a single connection wherein the inside CVE 

#curl https://access.redhat.com/errata/RHSA-2019:1166 |grep --color -A 50 "CVEs" |grep -o "CVE-.*\." |sed 's/\.//g'


Wherein the acquired security type from a single connection order inside

#curl https://access.redhat.com/errata/RHSA-2019:2462 |grep --color -o "Security Advisory:[[:space:]][[:alnum:]]*" |cut -d' ' -f3


Get wherein Description (described below) from a single connection order inside

#curl https://access.redhat.com/errata/RHSA-2019:2462 |grep --color -A 1  "<h2>Description</h2>" |grep  -E '^[[:space:]]+<p>' |sed -r 's@^[[:space:]]+@@g' |grep -o --color "^<p>.*Security Fix" |sed -r 's@<BR /><P>Security Fix@@g' |sed -r 's@<BR />@@g' |sed -r 's@<p>@@g'


Of course, this eleven links is time consuming, this time we write a shell script one by one traverse the 100 links the data to get the data we want

The first way (this way inspiration comes from the round robin with a shift of $ 1, that is, when we run the script, there are multiple parameters, each parameter involved only take the first script is run, the end of the run, a Round Robin, kicked out of the first argument, the second argument becomes the first parameter, and then run the script involved, and so on, until all the parameters involved in the completion of all):

We create an executable file in the / tmp directory #nano ceshishift.sh to edit:

#!/bin/bash

echo -e "binhao:`echo $1 |cut -d'/' -f5` \nlianjie:$1 \nCVEs:`curl $1 |grep --color -A 50 "CVEs" |grep -o "CVE-.*\." |sed 's/\.//g'` \nanquanleixing:`curl $1 |grep --color -o "Security Advisory:[[:space:]][[:alnum:]]*" |cut -d' ' -f3`  \nDescription:`curl $1 |grep --color -A 1  "<h2>Description</h2>" |grep  -E '^[[:space:]]+<p>' |sed -r 's@^[[:space:]]+@@g' |grep -o --color "^<p>.*Security Fix" |sed -r 's@<BR /><P>Security Fix@@g' |sed -r 's@<BR />@@g' |sed -r 's@<p>@@g'`"

shift

.

.

100 times

After saving the file to add permissions #chmod + x 

Setting a variable a, the value assigned to it 100 links # a = `cat test1.txt`

Then we started to run the script # / ceshishift.sh $ a can get the data we want something like the following:

image.png

Although the above view by polling can be done, but you need to write the code above 100, which a lot of friends, so it is easy to achieve the effect we want, and continue down

The second method (here we use a for loop):

We create an executable file in the / tmp directory #nano ceshifor.sh to edit:

#!/bin/bash


a=`cat test1.txt`

for LJ in $a;

     do

     echo -e "binhao:`echo $LJ |cut -d'/' -f5` \nlianjie:$LJ \nCVEs:`curl $LJ |grep --color -A 50 "CVEs" |grep -o "CVE-.*\." |sed 's/\.//g'` \nanquanleixing:`curl $LJ |grep --color -o "Security Advisory:[[:space:]][[:alnum:]]*" |cut -d' ' -f3`  \nDescription:`curl $LJ |grep --color -A 1  "<h2>Description</h2>" |grep  -E '^[[:space:]]+<p>' |sed -r 's@^[[:space:]]+@@g' |grep -o --color "^<p>.*Security Fix" |sed -r 's@<BR /><P>Security Fix@@g' |sed -r 's@<BR />@@g' |sed -r 's@<p>@@g'`";

     done


Save and exit, add to the file permissions #chmod + x

Run the script # / ceshifor.sh |. Tee linux100.txt can print 100 and the number corresponding to the data saved to eleven linux100.txt file on the screen, for example,

image.png


There are many ways to do this, but based on my existing knowledge of the above-mentioned amount is completed, many of the latter in terms of my stock of knowledge I will be coming up and then upload additional modifications, such as may be used for example to use a function or reptile, this case my friend with a Python script reptiles can achieve the full effect of the subject required, and I can only achieve the above functions to obtain the required data, how the data into spreadsheet programs required by command or other means, also We need time to sort out. Now I will reptile how my friend code is distributed in the form of pictures at:

image.png

image.png

image.png

image.png

image.png

image.png

FIG effect is a .xlsx file automatically generated:

image.png

Guess you like

Origin blog.51cto.com/1344946553/2430521