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
相关推荐
csdn_aspnet3 小时前
TCP/IP协议栈深度解析:从基石到前沿
服务器·网络·tcp/ip
lcreek3 小时前
Linux信号机制详解:阻塞信号集与未决信号集
linux·操作系统·系统编程
shandianchengzi3 小时前
【记录】Tailscale|部署 Tailscale 到 linux 主机或 Docker 上
linux·运维·docker·tailscale
John Song4 小时前
Linux机器怎么查看进程内存占用情况
linux·运维·chrome
sichuanwuyi4 小时前
Wydevops工具的价值分析
linux·微服务·架构·kubernetes·jenkins
持戒波罗蜜4 小时前
ubuntu20解决intel wifi 驱动问题
linux·驱动开发·嵌入式硬件·ubuntu
不做无法实现的梦~5 小时前
使用ros2来跑通mid360的驱动包
linux·嵌入式硬件·机器人·自动驾驶
梁辰兴5 小时前
计算机网络基础:虚拟专用网
服务器·网络·计算机网络·vpn·虚拟专用网·计算机网络基础·梁辰兴
点云SLAM5 小时前
C++内存泄漏检测之Windows 专用工具(CRT Debug、Dr.Memory)和Linux 专业工具(ASan 、heaptrack)
linux·c++·windows·asan·dr.memory·c++内存泄漏检测·c++内存管理