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
相关推荐
去码头整点薯条9817 分钟前
网络实验报告7
网络
汤愈韬18 分钟前
四种 NAT 类型详解|透彻理解 NAT 穿越原理(全锥 / 受限锥 / 端口受限锥 / 对称 NAT)
网络·网络协议·安全·网络安全·security
nanaki5021321 分钟前
04-LWIP(网络数据包PBUF)
网络·lwip
阿洛学长22 分钟前
VMware安装虚拟机教程(超详细)
java·linux·开发语言
YOU OU25 分钟前
Linux基本使用和程序部署
linux·运维·服务器
AI行业学习34 分钟前
PuTTY 工具下载部署、基础配置及 SSH 远程服务器连接完整操作指南Windows 平台 【2026.6.1】
运维·windows·ssh
jiayong2334 分钟前
CI/CD深度解析01-核心概念与原理
运维·git·ci/cd
fred_kang35 分钟前
如何找到 Linux 服务器上某个 URL 路径对应的实际部署位置
linux·运维·服务器
cc4422bb1 小时前
bgp练习
网络
allnlei1 小时前
两种 AAC 码流封装详解:Raw(ASC) vs ADTS
网络·aac