记录2——检查 patch 升级之后的各种版本shell script

任务需求:需要把patch升级后的系统检查所有相关已经升级的RPM的版本检查是否匹配实际patch
升级步骤:如果原有系统有安装的RPM则patch中包含的需要升级的包则自动升级;如果原有系统没有安装RPM,则patch中包含的需要升级的RPM可以忽略
实际脚本思路:先从系统中找到已经安装的rpm包,再通过rpm的包名与需要升级的patch匹配,名字匹配上再进行版本检测
该脚本还有有很多可以改进的地方(如有不好地方尽情指正)


# 	This program shows the user's choice
# History:
# Author :Murphy Ma
# Create: 2014/08/29
# Modify: 2014/09/12
WORKSPACE=`pwd`
RealInstalledPackage=$WORKSPACE/RealInstalledPackage
NeedCheckPackage=$WORKSPACE/NeedCheckPackage
RealInstalledPackage_Name=$WORKSPACE/RealInstalledPackage_Name
a=`date  +%Y%m%d%H%M%S`
realcheckpackage=$WORKSPACE/realcheckpackage$a
echo $RealInstalledPackage $NeedCheckPackage
echo "please enter a check item to verify thich rpm you will check:	\n\n"
echo "you can choose below item :\n
	Linux-Kernel
	Mozilla
	Samba
	Bind
	Xinetd
	Puppet
	Glibc
	Python
	CUPS
	openssl-certs
	openSSH
	openSSL
	ImageMagick
	Ruby
	Mutt	
	Sudo
	Coreutils
	Curl
	Libtiff
	Libxslt
	Libxml2
	xorg-x11-libX11
	xorg-x11-libXext
	xorg-x11-libXt
	net-snmp
	fastjar
	lcms
	gpg2
	krb5
	Gnutls
	Lighttpd	
	exit
     "
until [ "$item" == "exit" ]
do
	echo "======================================="
	read -p "input a chect item: " item
	echo "this round is to check rpm: " $item
	case $item in
	"Linux-Kernel")
	rpm -qa |grep -E  'kernel|xen-kmp-default' -i > $RealInstalledPackage
	;;
	"Mozilla")	
	rpm -qa |grep -E  'mozilla|libfreebl|libsoftokn' -i > $RealInstalledPackage
	;;
	"Samba")
	rpm -qa |grep -E 'samba|ldapsmb|libldb1|libsmbclient0|libtalloc2|libtdb1|libtevent0|libwbclient0' -i > $RealInstalledPackage
	;;
	"Bind")
	rpm -qa |grep 'bind' -i > $RealInstalledPackage
	;;
	"Xinetd")
	rpm -qa |grep 'xinetd' -i > $RealInstalledPackage
	;;
	"Puppet")
	rpm -qa |grep 'puppet' -i > $RealInstalledPackage
	;;
	"Glibc")
	rpm -qa |grep -E 'glibc|nscd' -i > $RealInstalledPackage
	;;
	"Python")
	rpm -qa |grep 'python' -i > $RealInstalledPackage
	;;
	"CPUS")
	rpm -qa |grep 'cups' -i > $RealInstalledPackage
	;;
	"openssl-certs")
	rpm -qa |grep -E 'openssl-certs' -i > $RealInstalledPackage
	;;
	"openSSH")
	rpm -qa |grep 'openssh' -i > $RealInstalledPackage
	;;
	"openSSL")
	rpm -qa |grep -E 'libopenssl|openssl' -i > $RealInstalledPackage
	;;
	"ImageMagick")
	rpm -qa |grep 'libMagickCore1' -i > $RealInstalledPackage
	;;
	"Ruby")
	rpm -qa |grep 'ruby' -i > $RealInstalledPackage
	;;
	"Mutt")
	rpm -qa |grep 'mutt' -i > $RealInstalledPackage
	;;
	"Sudo")
	rpm -qa |grep 'sudo' -i > $RealInstalledPackage
	;;
	"Coreutils")
	rpm -qa |grep 'coreutils' -i > $RealInstalledPackage
	;;
	"Curl")
	rpm -qa |grep -E 'curl|libcurl4' -i > $RealInstalledPackage
	;;
	"Libtiff")
	rpm -qa |grep -E 'libtiff3|tiff' -i > $RealInstalledPackage
	;;
	"Libxslt")
	rpm -qa |grep 'libxslt' -i > $RealInstalledPackage
	;;
	"Libxml2")
	rpm -qa |grep 'libxml2' -i > $RealInstalledPackage
	;;
	"xorg-x11-libXext")
	rpm -qa |grep 'xorg-x11-libXext' -i > $RealInstalledPackage
	;;
	"xorg-x11-libX11")
	rpm -qa |grep 'xorg-x11-libX11' -i > $RealInstalledPackage
	;;
	"xorg-x11-libXt")
	rpm -qa |grep 'xorg-x11-libXt' -i > $RealInstalledPackage
	;;
	"net-snmp")
	rpm -qa |grep -E 'snmp|libsnmp15' -i > $RealInstalledPackage
	;;
	"fastjar")
	rpm -qa |grep 'fastjar' -i > $RealInstalledPackage
	;;
	"lcms")
	rpm -qa |grep 'lcms' -i > $RealInstalledPackage
	;;
	"gpg2")
	rpm -qa |grep 'gpg2' -i > $RealInstalledPackage
	;;
	"krb5")
	rpm -qa |grep 'krb5' -i > $RealInstalledPackage
	;;
	"Gnutls")
	rpm -qa |grep 'gnutls' -i > $RealInstalledPackage
	;;
	"Lighttpd")
	rpm -qa |grep 'lighttpd' -i > $RealInstalledPackage
	;;
	"*")
	echo "Usage $item {Linux-Kernel|Mozilla|Samba|Bind|Xinetd|Puppet|Glibc|Python|CUPS|openssl-certs|openSSH|openSSL|ImageMagick|Ruby|Mutt|Sudo|Coreutils|Curl|Libtiff|Libxslt|Libxml2|xorg-x11-libX11|xorg-x11-libXext|xorg-x11-libXt|net-snmp|fastjar|lcms|gpg2|krb5|Gnutls|Lighttpd}"
	;;
	esac
	cat $RealInstalledPackage | sed 's/\(.*\)-\(.*-\)/\1    \2/' |awk '{print $1}' > $RealInstalledPackage_Name
	for item_name in `cat $RealInstalledPackage_Name`
	do		
		##add a @ in the head of item_name and use @ replase the last second separator -
		need_tmp_first=`cat $NeedCheckPackage |sed 's/\(.*\)-\(.*-\)/\1@\2/' |sed 's/^/@/g'|grep  @$item_name@` 
		echo "$need_tmp_first" 
		if [ -n "$need_tmp_first" ] ; then
			need_tmp_second=${need_tmp_first:1}
			need_tmp=${need_tmp_second/@/-}
			echo "'$need_tmp' should be checked ,and continue to check version"
			version_need_tmp=`cat $NeedCheckPackage |grep $need_tmp |sed 's/-/  /g' |awk '{print $(NF-1)}'`
			release_need_tmp=`cat $NeedCheckPackage |grep $need_tmp |sed 's/-/  /g' |awk '{print $NF}'`
			version_real_tmp=`rpm -qi $need_tmp |grep Version |awk 'NR==1{print $3}'`
			release_real_tmp=`rpm -qi $need_tmp |grep Release |awk 'NR==1{print $3}'`
			if [ "$version_need_tmp" == "$version_real_tmp" ] && [ "$release_need_tmp" == "$release_real_tmp" ]; then
				echo "patch:'$need_tmp' is installed right, you have successfull"
				echo "$need_tmp" >> $realcheckpackage
			else
				echo "patch:'$need_tmp' is installed wrong, you should check it"
				exit 1
			fi	
		fi
	done

done


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值