Linux脚本实战之检查软件包安装

Linux脚本实战之检查软件包安装

  • 一、脚本要求
  • 二、脚本内容
  • 三、运行脚本

一、脚本要求

1.检查本机是否安装httpd
2.已安装,则输出“httpd is already installed”,未安装则显示“httpd is not installed”
3.已安装,则同时显示httpd主配置文件,未安装,则安装vsftp服务所需安装包
4.检查是否安装httpd前,先检查yum仓库是否配好,未配好,提示未配置yum仓库。

二、脚本内容

#!/bin/bash
##########################################################
#File Name:yum.sh
#Version:V1.0
#Aurhor:
#Emali:
#Created Time:2021-05-02 23:24:32
#Description:
##########################################################



#! /bin/bash
yum repolist all |grep enable &> /dev/null
if [ $? = 0 ] ; then
      yum list installed |grep httpd &> /dev/null
          if [ $? = 0 ];then
               rpm -qc httpd
               echo "httpd is already installed"
          else
               echo "httpd is not installed"
               yum install -y vsftpd &> /dev/null
          fi
else
         echo "Yum warehouse not configured"
fi


三、运行脚本

1.已安装httpd

[root@control scripts]# 
[root@control scripts]# ./yum.sh 
Last metadata expiration check: 0:33:49 ago on Sun 02 May 2021 11:25:46 PM CST.
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-optional.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
httpd is already installed

2.未安装httpd

[root@control scripts]# ./yum.sh 
Last metadata expiration check: 0:35:51 ago on Sun 02 May 2021 11:25:46 PM CST.
httpd is not installed
[root@control scripts]# yum list installed |grep vsftpd
vsftpd.x86_64                                    3.0.3-28.el8                                         @AppStream 

你可能感兴趣的:(Linux,linux,运维,shell)