检查安装包是否安装成功——for语句+if判断

脚本作用是检查软件包组,判断包组是否安装,若未安装则自动安装。

#!/bin/bash
cur_data=`date +%Y-%m-%d`
INSTALL="base-x system-tools network-tools telnet.service"
yum groups list hidden >>/tmp/$(hostname)_baseline_check__$cur_data.log
for PKG in $INSTALL
do
    yum groups list hidden $PKG |grep "Installed Groups" > /dev/null 2>&1
if [ $? -ne 0 ];then
    echo "$PKG is Unsuccessful !!! 未安装" >>/tmp/$(hostname)_shell__$cur_data.log
    yum -y groups install $PKG > /dev/null 2>&1
    if [ $? -ne 0 ];then
        echo "$PKG is Unsuccessful !!! 安装失败" >>/tmp/$(hostname)_shell__$cur_data.log
    else
        echo "$PKG is Unsuccessful !!! 已修复" >>/tmp/$(hostname)_shell__$cur_data.log
    fi
else
    echo "$PKG is successful"
fi
done

你可能感兴趣的:(Shell,linux)