1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间
创建jiancha.sh文件
#!/bin/bash
###############################################################
# File Name: jiancha.sh
# Version:V1.0
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx1
# Created Time : 2023-05-21 19:48:06
# Description:
##############################################################
mb=`df -m /| awk 'NR==2{print $4}'
gb=$[mb/1024]
if [ "$gb" -lt 20 ]
then
echo "您最近的磁盘空间已经小于20G,请及时查看!"" mail -s "WORNING!" rootalocalhost
2、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
创建一个shell脚本写入
#!/bin/bash
###############################################################
# File Name: jianchal.sh
# Version: V1.0
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx/
# Created Time : 2023-05-21 19:55:45
# Description:
##############################################################
rpm http=`rpm -qa httpd wC -l'
if [ $rpm http -ge 1 ]
then
systemctl start httpd;
else
yum install -y httpd;
systemctl start httpd;
fi
rpm firewall=`rpm -qa firewalld |wc -l'
if [ $rpm firewall -ge 1 ]
then
systemctl start firewalld;
firewall-cmd --add-service=http --permanent;
else
yum install -y firewalld;
systemctl start firewalld;
firewall-cmd --add-service=http --permanent;
fi
ps ef= ps -ef l! grep "httpd" | wc -l’
port web=`ss -lntup | grep -w"80"| wc -l’ if [ $ps ef -ge 2 ] && [ $port web -ge 2 ]
then
echo"web服务已运行!"
else
echo "稍后为您开启web服务!"
systemctl start httpd;
fi
3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
1.将错误输出输出到/dev/null
具体命令如下:
#!/bin/bash
##############################################################
# File Name: jiancha2.sh
# Version: V1.0
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx/
# Created Time : 2023-05-21 19:58:37
# Description:
##############################################################
curl 192.168.233.128 > /dev/null 2>&1
if [ $? -eq θ ]
then
echo "web server is running!"
else
exit 12
fi