shell腳本:自動搭建yum(升級版)
阿新 • • 發佈:2018-01-10
oot list 測試 url exit follow yum all ble
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 [root@sv7 ~]# ./testyum.sh
YUM已經搭建完成
共有軟件包:
repolist: 4,620
前面寫過關於自動搭建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/*
YUM已經搭建完成
共有軟件包:
repolist: 4,620
shell腳本:自動搭建yum(升級版)