实战1
判断主机存活三次机会
请尝试使用三种方式书写ping脚本
1.主机地址已知
2.在线主机提示一次在线即可
3.不在线主机,不要ping失败超过三次,再确认主机不在线
示例1
ping_count3_1.sh
#!/usr/bin/bash
#ip_list=“10.18.40.1 10.18.42.127 10.18.42.8 10.18.42.5”
while read ip
do
for count in {1…3}
do
ping -c1 -W1 $ip &>/dev/null
if [
?
−
e
q
0
]
;
t
h
e
n
e
c
h
o
"
? -eq 0 ];then echo "
?−eq0];thenecho"ip ping is ok."
break
else
echo “$ip ping is failure:
c
o
u
n
t
"
f
a
i
l
c
o
u
n
t
[
count" fail_count[
count"failcount[count]=$ip
fi
done
if [ KaTeX parse error: Expected '}', got '#' at position 2: {#̲fail_count[*]} …{fail_count[1]} ping is failure!”
unset fail_count[*]
fi
done <ip.txt
示例2
ping_count3_2.sh
#!/usr/bin/bash
while read ip
do
fail_count=0
for i in {1…3}
do
ping -c1 -W1 $ip &>/dev/null
if [
?
−
e
q
0
]
;
t
h
e
n
e
c
h
o
"
? -eq 0 ];then echo "
?−eq0];thenecho"ip ping is ok."
break
else
echo “$ip ping is failure: $i”
let fail_count++
fi
done
if [
f
a
i
l
c
o
u
n
t
−
e
q
3
]
;
t
h
e
n
e
c
h
o
"
fail_count -eq 3 ];then echo "
failcount−eq3];thenecho"ip ping is failure!"
fi
done <ip.txt
示例3
ping_count3_3.sh
#!/usr/bin/bash
ping_success() {
ping -c1 -W1 $ip &>/dev/null
if [
?
−
e
q
0
]
;
t
h
e
n
e
c
h
o
"
? -eq 0 ];then echo "
?−eq0];thenecho"ip is ok."
continue
fi
}
while read ip
do
ping_success
ping_success
ping_success
echo “$ip ping is failure!”
done <ip.txt
实战2
在线部署网校系统
edusoho.sh
#!/bin/bash
#install edusoho
Mysql_Pass=123
#update
#yum update
#epel
yum -y install epel-release
#env
yum -y install bash-completion vim wget
systemctl restart firewalld
systemctl enable firewalld
setenforce 0
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
#LAMP
yum -y install httpd
yum -y install
php php-cli
php-curl
php-fpm
php-intl
php-mcrypt
php-mysql
php-gd
php-mbstring
php-xml
php-dom
yum -y install mariadb-server mariadb
yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mod_xsendfile-0.12-10.el7.x86_64.rpm
#apache
rm -rf /etc/httpd/conf.d/welcome.conf
#sed -ri ‘s/Listen 80/Listen 8080/’ /etc/httpd/conf/httpd.conf
systemctl enable httpd
#mysql
systemctl start mariadb
systemctl enable mariadb
mysqladmin -uroot password “ M y s q l P a s s " m y s q l − u r o o t − p " Mysql_Pass" mysql -uroot -p" MysqlPass"mysql−uroot−p"Mysql_Pass” -e “create database edusoho”
#php
sed -ri ‘s/post_max_size = 8M/post_max_size = 1024M/’ /etc/php.ini
sed -ri ‘s/memory_limit = 128M/memory_limit = 1024M/’ /etc/php.ini
sed -ri ‘s/upload_max_filesize = 2M/upload_max_filesize = 1024M/’ /etc/php.ini
sed -ri ‘s#;date.timezone =#date.timezone = Asia/ShangHai#’ /etc/php.ini
systemctl start php-fpm
systemctl enable php-fpm
#edusoho
wget http://download.edusoho.com/edusoho-7.5.12.tar.gz
tar xf edusoho-7.5.12.tar.gz
cp -rf edusoho /var/www/
chown -R apache.apache /var/www/edusoho/
rm -rf /var/www/html/index.html
sed -ri ‘s#DocumentRoot “/var/www/html”#DocumentRoot “/var/www/edusoho/web”#’ /etc/httpd/conf/httpd.conf
cat >>/etc/httpd/conf/httpd.conf <<EOF
<Directory “/var/www/edusoho/web”>
AllowOverride All
Require all granted
EOF
systemctl restart httpd
systemctl restart php-fpm