Linux shell脚本实现yum源配置(用户交互版和预定义配置版)

74 篇文章 0 订阅
68 篇文章 0 订阅

本博客是我自制的两个yum配置脚本,一个是用户交互版本,用户可以在脚本运行过程中指定各种配置细节;另一种是将各种配置已经预定义好了,适合大规模配置,下面我来看脚本吧,其实有Linux shell基础的通知应该闭着眼睛都能看懂的。

yum源配置脚本用户交互版

#!/bin/bash
#首先展示用户欢迎界面
echo '*********************************************************'
echo '*                                                       *'
echo '*          Welcome to yum sources configration          *'
echo '*                                                       *'
echo '*********************************************************'
echo -e '\n'
#脚本开始询问用户是否要清空yum目录下的文件
read -p 'please confirm to empty the directory /etc/yum.repo.d/(yes/no): ' choice
if [ $choice = 'yes' ] || [ $choice = 'Y' ] || [ $choice = 'y' ] 
then
#是的,清空
rm -rf /etc/yum.repos.d/*
echo 'Directory cleaned!'
elif [ $choice = 'no' ] || [ $choice = 'N' ] || [ $choice = 'n' ]
then
echo 'You chose to reserver files in  /etc/yum.repo.d/ !'
else
echo 'Unmatched input, next command will be conducted!'
fi
#指定你的源文件名称
read -p 'Please specify your repo file name(eg:myrepo.repo): ' repoName
fullPath=/etc/yum.repos.d/${repoName}
if [ -e $fullPath  ]
then
#文件已经存在则提示存在了
echo 'File exists!'
else
#文件不存在则创建并给出提示
touch /etc/yum.repos.d/${repoName}
echo 'File not exists, script has create it!'
fi
#用户输入源名称,然后写入
read -p 'Please input your yum source name(eg:[halo]): ' sourceName
echo -e '\n'
echo [$sourceName] >>/etc/yum.repos.d/${repoName}
#用户输入源描述,然后写入
read -p 'Please input your yum source description: ' sourceDesc 
echo 'name='$sourceDesc >>/etc/yum.repos.d/${repoName}

echo 'Please input your yum source baseurl: '
echo -e '\n'
echo ' eg1(for http):http://172.25.254.36/iso/'
echo ' eg2(for ftp):ftp://172.25.254.36/iso/'
echo ' eg3(for file):file:///var/www/html/rhel7.1'
#用户输入源指向,然后写入
read baseurl
echo 'baseurl='$baseurl>>/etc/yum.repos.d/${repoName}
#用户输入gpgcheck值,然后写入
read -p 'Please input your gpgcheck number(0|1): ' gpgcheck
echo 'gpgcheck='${gpgcheck} >>/etc/yum.repos.d/${repoName}
echo 'Config OK!'
#清空yum缓存,进行更新
yum clean all

yum源配置脚本预定义配置版

#!/bin/bash
#echo '*********************************************************'
#echo '*                                                       *'
#echo '*          Welcome to yum sources configration          *'
#echo '*                                                       *'
#echo '*********************************************************'
#清空源目录
rm -rf /etc/yum.repos.d/*
#创建源文件并写入预定义的配置信息
cat >> /etc/yum.repos.d/yum.repo <<end
[yum-configured-by-lockey]
name=rhel7.2 iso
baseurl=http://172.25.254.36/iso
gpgcheck=0
end
#更新yum配置
yum clean all

脚本虽然简单,但毕竟算个脚本,总比手动一个个输入强很多啊!!!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值