[root@server ~]# vim /etc/s-nail.rcsetfrom=2962273654@qq.com # 你的邮箱地址setsmtp=smtp.qq.com # 发邮件协议set smtp-auth-user=2962273654@qq.com # 你的邮箱地址set smtp-auth-password=wmdcllnz****rdgii # 授权码 set smtp-auth=login
编写脚本
[root@server ~]# vim youjian.sh#!/bin/bashd=$(df -m |grep -w "/"|tr -s " "|cut -d " " -f4)if(($d <20000))thenecho"磁盘容量低"| mail -v -s "磁盘容量"2962273654@qq.com
fi
设置定时任务
判断阿帕奇是否运行
安装阿帕奇
[root@server ~]# yum install httpd
基于进程号判断HTTP是否运行
编写脚本
[root@server ~]# vim http.sh#!/bin/bashps=$(ps -ef |grep httpd |grep -v grep|wc -l)if(($ps>0))thenecho" httpd is running"elseecho"httpd is not running"
systemctl restart httpd
systemctl restart firewalld
firewall-cmd --permanent --zone=public --add-service=http > /dev/null
echo"httpd is running"fi
测试
基于端口号进行判断阿帕奇是否启动
编写脚本
[root@server ~]# vim http1.sh#!/bin/bashps=$(netstat -lntup |grep80|wc -l)if(($ps>0))thenecho"httpd is running"elseecho"httpd is not running"
systemctl restart httpd
systemctl restart firewalld
firewall-cmd --permanent --zone=public --add-service=http > /dev/null
echo"httpd is running"fi
测试
curl进行web服务器的访问
编写脚本
[root@server ~]# vim http2.sh#!/bin/baship=$(ip a |sed -n "/inet/p"|sed -n "3p"|cut -d / -f1 |tr -s " "|cut -d " " -f3)curl$ip> /dev/null
if(($?==0))thenecho"web service is running"elseecho"web service is not running"exit12fi