Linux脚本实战之检查软件包安装
Posted jks212454
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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脚本实战统计 Linux 进程相关数量信息
Linux之shell脚本实战批量上传docker镜像到华为云容器镜像仓库