shell——if条件判断

安装apache

vim install_apache.sh

#!/usr/bin/bash
ping -c1 www.baidu.com &>/dev/null    #检测网通不通,不通直接退出
if [ $? -eq 0 ];then
	echo "connect:unreachable"
	exit
fi
yum -y install httpd
systemctl start httpd
systemctl enable httpd
firewall -cmd --permanent -add-service=http
firewall -cmd --permanent -add-service=https
firewall -cmd --reload
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
setenforce 0

vim install_apache2.sh

#!/usr/bin/bash
gateway=192.168.122.1
ping -c1 www.baidu.com &>/dev/null
if [ $? -eq 0 ];then
	yum -y install httpd
	systemctl start httpd
	systemctl enable httpd
	firewall -cmd --permanent -add-service=http
	firewall -cmd --permanent -add-service=https
	firewall -cmd --reload
	sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
	setenforce 0
elif ping -c1 $gateway &>/dev/null;then#ping网关,这里开始排查ping不通baidu的网络原因
	echo "check dns..."
else
	echo "check ip address!"
fi

yum配置源

#!/usr/bin/bash
#yum config
yum_server=10.18.40.100
os_version=`cat /etc/redhat-release |awk '{print $4}' \
|awk -F"." '{print $1"."$2}'`#其中-F"."是以.作为分隔符
[ -d /etc/yum.repos.d ] || mkdir /etc/yum.repos.d/bak #如果/etc/yum.repos.d不存在 则创建 /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak

if [ "$os_version" = "7.3" ];then
	cat >/etc/yum.repos.d/centos7u3.repo <<-EOF
	[centos7u3]
	name=centos7u3
	baseurl=ftp://$yum_server/centos7u3
	gpgcheck=0
	EOF
	echo "7.3 yum configure"
elif [ "$os_version" = "6.8" ];then
	curl -o /etc/yum.repos.d/centos6u8.repo ftp://$yum_server/centos6u8.repo
elif [ "$os_version" = "5.9" ];then
	curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
else
	echo "error"
fi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值