centos使用shell判断版本号安装相对版本的yum源
作者:
南南宫问天 | 来源:发表于
2020-04-08 21:20 被阅读0次root@db scripts]# cat version.sh
#!/bin/bash
ver=`cat /etc/redhat-release | awk '{print $(NF-1)}'`
if [ ${ver%%.*} -eq 7 ];then ##如果版本=7
which wget > /dev/null 2>&1 ##如果没有.就安装wget
[ $? -ne 0 ] && yum -y install wget
wait ##等上面语句结束
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ##备份原有的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
elif [ ${ver%%.*} -eq 8 ];then
which wget > /dev/null 2>&1
[ $? -ne 0 ] && yum -y install wget
wait
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
else
which wget > /dev/null 2>&1
[ $? -ne 0 ] && yum -y install wget
wait
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
fi
本文标题:centos使用shell判断版本号安装相对版本的yum源
本文链接:https://www.haomeiwen.com/subject/kjixmhtx.html
网友评论