ce第六次作业

1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间。

复制代码
[root@Server ~]# yum install -y mailx
[root@Server ~]# yum -y install bind-utils
[root@Server ~]# vim /etc/mail.rc
set from=15339232034@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=15339232034@163.com
set smtp-auth-password=PVw7kZuYqpjYij3E
set smtp-auth-login

[root@Server ~]# vim remaining_disks.sh
#/bin/bash
remaining_disks=$(df -h | grep "\/$" | cut -d" " -f4 | cut -d"G" -f1)
msg="当前磁盘空间小于20g,请及时处理"
if [ ${remaining_disks} -lt 20 ]
then
        echo $msg | mail -s "内存报警" 15339232034@163.com
fi

[root@Server ~]# crontab -l
0 0 * * * /usr/bin/sh /root/remaining_disks.sh

​ 2、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。

复制代码
[root@Server ~]# vim nginx_process.sh
#/bin/bash
pro=$(netstat -lntup |grep -w 80 |wc -l)
if [ $pro -gt 0 ]
then
        echo "the nginx services is running"
else
        echo "the nginx services is not running"
        systemctl start nginx
        systemctl start firewalld
        firewall-cmd --permanent --zone=public --add-port=80/tcp &>/dev/null
        firewall-cmd --permanent --zone=public --add-service=http &> /dev/null
        firewall-cmd --reload &>/dev/null
        echo "nginx is already running"
fi
       

[root@Server ~]# vim nginx_process2.sh 
#!/bin/bash
pro=$(netstat -lntup | grep -w 80 | wc -l)
if [ $pro -gt 0 ]
then
        echo "nginx is running"
else
        echo"nginx is not running"
        systemctl start nginx
        systemctl start firewalld
        firewall-cmd --permanent --zone=public --add-service=http &>/dev/null
        firewall-cmd --permanent --zone=public --add-port=80/tcp &>/dev/null
fi

[root@Server ~]# systemctl stop nginx
相关推荐
安科士andxe1 小时前
深入解析|安科士1.25G CWDM SFP光模块核心技术,破解中长距离传输痛点
服务器·网络·5g
YJlio4 小时前
1.7 通过 Sysinternals Live 在线运行工具:不下载也能用的“云端工具箱”
c语言·网络·python·数码相机·ios·django·iphone
CTRA王大大4 小时前
【网络】FRP实战之frpc全套配置 - fnos飞牛os内网穿透(全网最通俗易懂)
网络
小白同学_C4 小时前
Lab4-Lab: traps && MIT6.1810操作系统工程【持续更新】 _
linux·c/c++·操作系统os
今天只学一颗糖4 小时前
1、《深入理解计算机系统》--计算机系统介绍
linux·笔记·学习·系统架构
2601_949146534 小时前
Shell语音通知接口使用指南:运维自动化中的语音告警集成方案
运维·自动化
儒雅的晴天4 小时前
大模型幻觉问题
运维·服务器
testpassportcn5 小时前
AWS DOP-C02 認證完整解析|AWS DevOps Engineer Professional 考試
网络·学习·改行学it
Gofarlic_OMS5 小时前
科学计算领域MATLAB许可证管理工具对比推荐
运维·开发语言·算法·matlab·自动化
通信大师5 小时前
深度解析PCC策略计费控制:核心网产品与应用价值
运维·服务器·网络·5g