
1.判断磁盘空间
1.1安装Email服务
[root@server ~]yum install s-nail -y

1.2编写Email文件
[root@server ~]vim /etc/s-nail.rc
set from=1094293132@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=1094293132@qq.com
set smtp-auth-password=evjjizudsijzijec
set smtp-auth=login

1.3编写shell脚本查看磁盘空间
[root@server ~]vim disk1.sh
#!/bin/bash
disk=`df -m | grep -w "/" | tr -s " " | cut -d " " -f4`
str1="waring disk space lsee than 20G"
if [ "$disk" -lt 20000 ]
then
echo "$str1" | mail -s "$str1" 1094293132@qq.com
fi

1.4设置一个任务周期
[root@server ~]vim /etc/crontab
0 0 * * * root /bin/bash /root/disk1.sh

1.5测试,打开qq邮箱看是否收到邮件
[root@server ~]bash disk1.sh

2.判断web服务是否运行
2.1编写一个查看web是否运行起来的脚本,如果没有运行起来,则对web做一个运行操作
[root@server ~] vim web1.sh
#!/bin/bash
ps=`ps -ef | grep "httpd" | grep -v "grep" | wc -l`
if [ "$ps" -gt 0 ]
then
echo "httpd is already running"
else
echo "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 ~] bash web1.sh

3.使用curl命令看web启用了没有
3.1编写shell脚本
[root@server ~] vim web2.sh
#!/bin/bash
curl -s 192.168.74.129 > /dev/null
if (($?==0))
then
echo "web server is running"
else
echo "web not accessible"
exit 12
fi

3.2测试,运行脚本
[root@server ~] bash web2.sh
