Shell检查安装rpm包

Shell检查安装rpm包

Shell检查安装rpm包脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@hzvscmdb check]# vim check_rpm3.sh
###################RPM_CHECK#################
#!/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
done
exit 0
}
check_rpm $@

运行以下命令查看安装的包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@hzvscmdb check]# ./check_rpm3.sh binutils elfutils-libelf glibc glibc-common libaio libgcc libstdc++ make compat-libstdc++-33 elfutils-libelf-devel glibc-headers glibc-devel libgomp gcc gcc-c++ libaio-devel libstdc++-devel unixODBC unixODBC-devel sysstat
2.6.32-279.el6.x86_64
RPM version 4.8.0
binutils is installed
elfutils-libelf is installed
glibc is installed
glibc-common is installed
libaio is installed
libgcc is installed
libstdc++ is installed
make is installed
compat-libstdc++-33 is installed
elfutils-libelf-devel is installed
glibc-headers is installed
glibc-devel is installed
libgomp is installed
gcc is installed
gcc-c++ is installed
libaio-devel is installed
libstdc++-devel is installed
unixODBC is installed
unixODBC-devel is installed
sysstat is installed