您的位置:首页 > 运维架构 > Shell

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

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

1[root@sv7 ~]# 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
[root@sv7 ~]# chmod +x /root/testyum.sh

2 测试
已经搭建测试
[root@sv7 ~]# ./testyum.sh
YUM源已经安装

没有搭建测试
[root@sv7 ~]# rm -rf /etc/yum.repos.d/*
[root@sv7 ~]# ./testyum.sh
YUM已经搭建完成
共有软件包:
repolist: 4,620
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell