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
相关推荐
酉鬼女又兒1 分钟前
零基础入门计算机网络:网络层核心任务、三大关键问题、两种服务类型与 TCP/IP 网际层协议体系全解析
服务器·网络·网络协议·tcp/ip·计算机网络·php·求职招聘
Urbano23 分钟前
工装制作全流程科普:从面料到自动化生产
网络·人工智能
kong@react25 分钟前
Rocky Linux 10.2 全面解析:企业级 CentOS 替代方案及保姆级docker安装
java·linux·运维·docker
2401_8685347830 分钟前
网规笔记 | 真题解析:2018年11月软考网规-网络安全案例分析
网络
Gauss松鼠会1 小时前
【GaussDB】GaussDB重要通信参数汇总
服务器·网络·数据库·sql·性能优化·gaussdb·经验总结
凡人叶枫1 小时前
Effective C++ 条款07:为多态基类声明 virtual 析构函数
linux·c语言·开发语言·c++
睡不醒男孩0308231 小时前
第八篇:如何构建一站式 PostgreSQL 性能优化与智能管控平台?从盲目排查到 CLup 自动化运维演进
运维·postgresql·性能优化
超级无敌zhq1 小时前
后渗透痕迹清理:攻防对抗中的隐身术
网络·数据库·网络安全
凡人叶枫1 小时前
Effective C++ 条款10:令 operator= 返回一个 reference to *this
java·linux·服务器·开发语言·c++·effective c++
某林2121 小时前
Isaac Sim 5.1.0 无头服务器部署与 RTX 显存段错误排障全记录
运维·服务器·docker·容器·isaac