centos使用shell判断版本号安装相对版本的yum源

2020-04-08  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读