shell脚本:自动搭建yum(升级版)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本:自动搭建yum(升级版)相关的知识,希望对你有一定的参考价值。

前面写过关于自动搭建yum的脚本,感觉不够完善。下面这个脚本在前面的基础上加上判断,如果yum已经搭建好,那么不安装;没有搭建则安装。

1[[email protected] ~]# vim testyum.sh
脚本内容
#!/bin/bash
N=yum repolist | grep ‘repolist‘| awk ‘{print $2}‘
if [ $((N)) -gt 0 ]; then
echo "YUM源已经安装"
exit
elif [ $((N)) -eq 0 ];then
rm -rf /etc/yum.repos.d/*
echo "[110] //注意从此行开始到gpgcheck=0行都要顶头写,如果不是,那么yum文件会产生格式错误
name=110
baseurl=http://192.168.4.254/rhel7
enabled=1
gpgcheck=0 " > /etc/yum.repos.d/110.repo
yum clean all &> /dev/null
echo "YUM已经搭建完成"
echo "共有软件包:"
yum repolist | tail -1
fi
[[email protected] ~]# chmod +x /root/testyum.sh

2 测试
已经搭建测试
[[email protected] ~]# ./testyum.sh
YUM源已经安装

没有搭建测试
[[email protected] ~]# rm -rf /etc/yum.repos.d/*
[[email protected] ~]# ./testyum.sh
YUM已经搭建完成
共有软件包:
repolist: 4,620

以上是关于shell脚本:自动搭建yum(升级版)的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本:自动搭建yum

搭建yum仓库脚本

Shell脚本入门及搭建yum仓库脚本

Shell ❀ Linux系统自动挂载本地yum源并安装rpm依赖包

Shell ❀ Linux系统自动挂载本地yum源并安装rpm依赖包

Shell ❀ Linux系统自动挂载本地yum源并安装rpm依赖包