国家胸痛中心建设网站,海南建设厅评审网站,中国建设网站齐齐哈尔市,博客1、判断当前磁盘剩余空间是否有20G#xff0c;如果小于20G#xff0c;则将报警邮件发送给管理员#xff0c;每天检查一次磁盘剩余空间。
因为如果磁盘剩余空间小于20G需要报警发送邮件给管理员#xff0c;所以需要对管理员的邮箱进行设置
#xff08;1#xff09;首先…1、判断当前磁盘剩余空间是否有20G如果小于20G则将报警邮件发送给管理员每天检查一次磁盘剩余空间。
因为如果磁盘剩余空间小于20G需要报警发送邮件给管理员所以需要对管理员的邮箱进行设置
1首先安装软件
[rootserver scripts]# yum install -y s-nail2进入邮件配置文件中设置管理员邮件vim /etc/s-nail.rc
set from1281984647qq.com
set smtpsmtp.qq.com
set smtp-quth-user1281984647qq.com
set smtp-auth-passworddacqjvfivytdiagj
set smtp-authlogin
3尝试向管理员发送邮件 echo test 1 |s-nail -s title 1281984647qq.com 编写shell脚本free.sh将以下内容写入
if [ df -h | grep /$ | tr -s | cut -d -f4 | cut -dG -f1 -lt 20 ]
then echo 管理员快看看你的内存不够20G了 | s-nail -s title 1281984647qq.com
fi
4测试运行./free.sh 管理员成功的收到了内存不够的警告
5设置任务计划每天检查一次crontab -e
0 0 * * * sh /server/scripts/free.sh[rootserver scripts]# crontab -l
0 0 * * * sh /server/scripts/free.sh2、判断web服务是否运行
1查看进程的方式判断该程序是否运行
编写脚本vim check_httpd.sh
if [ ps -aux |grep httpd |grep -v grep | tr -s |cut -d -f8 |uniq | wc -l -lt 2 ]
then systemctl start httpd
else echo httpd服务已经运行了
fi
测试./check_httpd.sh
[rootserver scripts]# ./check_web.sh
[rootserver scripts]# ./check_web.sh
httpd服务已经运行了2通过查看端口的方式判断该程序是否运行如果没有运行则启动该服务并配置防火墙规则。
编写脚本vim check_httpd2.sh
if [ netstat -lnupt | grep 80 |wc -l -eq 0 ]
then systemctl start httpd;firewall-cmd --permanent --zonepublic --add-port80/tcp
else echo httpd服务已经启动
fi
测试./check_httpd2.sh
[rootserver scripts]# ./check_web2.sh
success
[rootserver scripts]# ./check_web2.sh
httpd服务已经启动3、使用curl命令访问第二题的web服务看能否正常访问如果能正常访问则返回web server is running如果不能正常访问返回12状态码。
编写脚本vim curl.sh
read -p 请输入一个网址 w
curl $w
if [ echo $? -eq 0 ]
then echo web server is running
else echo 状态码12
fi
测试./curl.sh
[rootserver scripts]# ./curl.sh
请输入一个网址www.baidu.com
web server is running[rootserver scripts]# ./curl.sh
请输入一个网址www.qweqweweqweweeressd.com
curl: (6) Could not resolve host: www.qweqweweqweweeressd.com
状态码12