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
相关推荐
人间打气筒(Ada)1 小时前
MySQL主从架构
服务器·数据库·mysql
落笔画忧愁e2 小时前
FastGPT快速将消息发送至飞书
服务器·数据库·飞书
小冷爱学习!2 小时前
华为动态路由-OSPF-完全末梢区域
服务器·网络·华为
技术小齐3 小时前
网络运维学习笔记 016网工初级(HCIA-Datacom与CCNA-EI)PPP点对点协议和PPPoE以太网上的点对点协议(此处只讲华为)
运维·网络·学习
ITPUB-微风3 小时前
Service Mesh在爱奇艺的落地实践:架构、运维与扩展
运维·架构·service_mesh
打不了嗝 ᥬ᭄3 小时前
Linux的权限
linux
落幕3 小时前
C语言-进程
linux·运维·服务器
深度Linux3 小时前
C++程序员内功修炼——Linux C/C++编程技术汇总
linux·项目实战·c/c++
chenbin5203 小时前
Jenkins 自动构建Job
运维·jenkins
java 凯4 小时前
Jenkins插件管理切换国内源地址
运维·jenkins