Skip to content

Instantly share code, notes, and snippets.

@victorbrca
Created December 9, 2022 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorbrca/93b5235fc2a4ee854f3126f84ab2eb21 to your computer and use it in GitHub Desktop.
Save victorbrca/93b5235fc2a4ee854f3126f84ab2eb21 to your computer and use it in GitHub Desktop.
Gets a list of available security updates on Red Hat with different display summaries
yum-check-security-updates () {
local OPTERR OPTIND OPT OPTARG v_usage v_help v_mode v_type v_update_list
v_usage="yum-check-security-updates [-s|-l|-c] -t [m[moderate]|i[important]|c[critical]]"
v_help="$v_usage
OPTIONS:
-s,[no arg]
Shows a summary (default option)
-l
Long listing
-c
List CVEs
-t [m|i|c]
Select update type as moderate, important or critical
-h,
This help menu
EXAMPLES:
Shows a summary (count) of all security updates available
$ yum-check-security-updates
Lists all security updates available
$ yum-check-security-updates -l
Lists all critical security updates available
$ yum-check-security-updates -l -t c
"
# OPTERR=0
while getopts ":slct:h" OPT ; do
case $OPT in
s) v_mode="summary" ;;
l) v_mode="long" ;;
c) v_mode="cve" ;;
t) v_type="$OPTARG" ;;
h) echo -e "$v_help" && return 0 ;;
*) echo "Unknown option" ; return 1 ;;
esac
done
v_mode="${v_mode:-summary}"
if [ "$v_type" ] ; then
case "$v_type" in
m|M|Moderate|moderate|mod*) v_type="Moderate" ;;
i|I|Important|important|imp*) v_type="Important" ;;
c|C|Critical|critical|cri*) v_type="Critical" ;;
*) echo 'Duhh!! Wrong option' ; return 1 ;;
esac
fi
echo -e "\n ** Getting the update list... Please wait a few secs\n"
if [[ "${v_mode^^}" == "CVE" ]] ; then
v_update_list="$(sudo yum updateinfo list cves)"
else
v_update_list="$(sudo yum updateinfo list sec)"
fi
case "$v_mode" in
"summary")
if [ "$v_type" ] ; then
echo "=> Here's a summary of all the security updates available to be installed:"
echo "${v_type}: $(echo "$v_update_list" | grep -c ${v_type})"
return 0
else
echo "=> Here's a summary of all the security updates available to be installed:"
for i in Critical Important Moderate Low None ; do
echo "${i}: $(echo "$v_update_list" | grep -c ${i})"
done
return 0
fi
;;
"long")
if [ "$v_type" ] ; then
echo "=> Here are all the available $v_type security updates:"
echo "$v_update_list" | grep --color=never "$v_type"
return 0
else
echo "=> Here are all the security updates available to be installed:"
echo "$v_update_list" | grep --color=never '/Sec'
return 0
fi
;;
"cve")
echo "=> Here are all the available CVE updates:"
echo "$v_update_list" | grep --color=never '/Sec'
return 0
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment