检查RPM包是否已经安装:
###################RPM_CHECK1################# -->仅仅是检查单个rpm包是否安装,未安装的不能自动安装 #!/bin/bash # check rpm is installed or not uname -r rpm --version echo P=${1?" must specify package name."} rpm -qa "$P" > t1 my_size=$( wc -l < t1 ) echo " Size of report file is $my_size lines" if [[ $( rpm -qa $P ) =~ ${P} ]] # if [[ $( rpm -qa $P ) == *${P}* ]] then echo " Package $P is installed." else echo " Package $P not found." fi exit 0 ###################RPM_CHECK1################# ###################RPM_CHECK2################# -->可以实现多种rpm包的检查,未安装的自动安装 #!/bin/bash #filename: check_rpm uname -r rpm --version check_rpm() { while (( $# > 0 )) do if ! rpm -q $1 &> /dev/null;then yum install $1 -y &>/dev/null if [ $? == 0 ];then echo "$1 install is success!" else echo "$1 is not in the systerm Packages!" fi fi shift #执行一次shift则去掉第一个参数,始终只需判断$1即可 done exit 0 } check_rpm $@ ###################RPM_CHECK2################# ###################RPM_CHECK3################# -->结合以上两个脚本 #!/bin/bash #filename: check_rpm uname -r rpm --version P=${1?" must specify package name."} #加入这一行表示必须需要输入一个有效的软件包名 check_rpm() { while (( $# > 0 )) do if ! rpm -q $1 &> /dev/null;then yum install $1 -y &>/dev/null if [ $? == 0 ];then echo "$1 install is success!" else echo "$1 is not in the systerm Packages!" fi else echo "$1 is installed" fi shift #执行一次shift则去掉第一个参数,始终只需判断$1即可 done exit 0 } ###################RPM_CHECK3#################检查RPM包是否已经安装
内容版权声明:除非注明,否则皆为本站原创文章。