目录
1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间。
2、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间。
vim df.sh
#!/bin/bash
disk_space=`df -h / |grep / | cut -d " " -f 9 |tr -d G`
echo "Your disk space is "$disk_space"G"
if [ "$disk_space" -lt "20" ]
then
echo " Warnning !!! You have less disk space than 20GB. Your dis space is "$disk_space"G " | mail -s "Warning " root
else
exit
fi
vim /etc/crontab
0 0 * * * root /root/test/df.sh
2、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
查看进程的方式判断该程序是否运行
vim pshttp.sh
#!/bin/bash
ps=`ps -ef | grep httpd | wc -l`
if [ "$ps" -gt 1 ]
then
echo "Httpd is start"
else
systemctl start httpd
firewall-cmd --add-port=80/tcp
fi
通过查看端口的方式判断该程序是否运行
vim porthttp.sh
#!/bin/bash
netstat -anp |grep -w 80 &>/dev/null
if [ "$?" -eq 0 ]
then
echo "Httpd is start"
else
systemctl start httpd
firewall-cmd --add-port=80/tcp
fi
3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
#!/bin/bash
curl 192.168.239.200 &>/dev/null
if [ "$?" -eq 0 ]
then
echo "server is running!!!"
else
exit 12
fi