[root@server ~]# vim disk.sh#!/bin/bashdisk=$(df-m|grep-w"/"|tr-s" "|cut-d" "-f4)str1="warning:disk space less than 20G!"if["$disk"-lt20000]thenecho"$str1"| mail -s"$str1"791204559@qq.com
fi
1.2 安装邮件服务
[root@server ~]# yum install s-nail -y[root@server ~]# vim /etc/s-nail.rc setfrom=791204559@qq.com
setsmtp=smtp.qq.com
set smtp-auth-user=791204559@qq.com
set smtp-auth-password=pzc18509170831
set smtp-auth=login
[root@server ~]# vim test.sh#!/bin/bashps=`ps-ef|grep httpd |grep-vgrep|wc-l`if["$ps"-gt0];thenecho"httpd is already running"elseecho"httpd not started,waiting...."
yum install httpd -y> /dev/null
systemctl start httpd
systemctl start firewalld
firewall-cmd --permanent--zone=public --add-service=http > /dev/null
firewall-cmd --permanent--zone=public --add-port=80/tcp > /dev/null
firewall-cmd --reload> /dev/null
echo"httpd is already running"fi
2.2 测试
[root@server ~]# sh test.sh
httpd is already running
3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
3.1 编写脚本
[root@server ~]# vim web.sh#!/bin/baship=`ip a |grep ens160 |grep inet |cut-d / -f1|tr-s' '|cut-d' '-f3`curl-s$ip> /dev/null
if(($?==0))thenecho"web server is running"elseecho"web not accessible"exit12fi
3.2 测试
[root@server ~]# sh web.sh
web server is running
[root@server ~]# systemctl stop httpd[root@server ~]# sh web.sh
web not accessible
[root@server ~]# echo $?12