• 【无标题】


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

    因为如果磁盘剩余空间小于20G需要报警发送邮件给管理员,所以需要对管理员的邮箱进行设置

    (1)首先安装软件:

    [root@server scripts]# yum install -y s-nail
    

    (2)进入邮件配置文件中设置管理员邮件:vim /etc/s-nail.rc

    1. set from=2363543991@qq.com

    2. set smtp=smtp.qq.com

    3. set smtp-quth-user=2363543991@qq.com

    4. set smtp-auth-password=dacqjvfivytdiagj

    5. set smtp-auth=login

    (3)尝试向管理员发送邮件: echo "test 1" |s-nail -s "title" 2363543991@qq.com

    编写shell脚本free.sh:将以下内容写入

    1. if [ "`df -h | grep /$ | tr -s " " | cut -d" " -f4 | cut -d"G" -f1`" -lt 20 ]

    2. then

    3. echo "管理员快看看你的内存不够20G了" | s-nail -s "title" 1281984647@qq.com

    4. fi

    (4)测试运行:./free.sh

    管理员成功的收到了内存不够的警告 !

    (5)设置任务计划每天检查一次:crontab -e

    0 0 * * * sh /server/scripts/free.sh
    
    1. [root@server scripts]# crontab -l

    2. 0 0 * * * sh /server/scripts/free.sh

    2、判断web服务是否运行

    (1)查看进程的方式判断该程序是否运行

    编写脚本:vim check_httpd.sh

    1. if [ "`ps -aux |grep httpd |grep -v grep | tr -s " " |cut -d " " -f8 |uniq | wc -l`" -lt 2 ]

    2. then

    3. systemctl start httpd

    4. else

    5. echo "httpd服务已经运行了"

    6. fi

    测试:./check_httpd.sh

    1. [root@server scripts]# ./check_web.sh

    2. [root@server scripts]# ./check_web.sh

    3. httpd服务已经运行了

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

    编写脚本:vim check_httpd2.sh

    1. if [ "`netstat -lnupt | grep 80 |wc -l`" -eq 0 ]

    2. then

    3. systemctl start httpd;firewall-cmd --permanent --zone=public --add-port=80/tcp

    4. else

    5. echo "httpd服务已经启动"

    6. fi

    测试:./check_httpd2.sh

    1. [root@server scripts]# ./check_web2.sh

    2. success

    3. [root@server scripts]# ./check_web2.sh

    4. httpd服务已经启动

    ​3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。

    编写脚本:vim curl.sh

    1. read -p "请输入一个网址:" w

    2. curl $w

    3. if [ "`echo $?`" -eq 0 ]

    4. then

    5. echo "web server is running"

    6. else

    7. echo "状态码12"

    8. fi

    测试:./curl.sh

    1. [root@server scripts]# ./curl.sh

    2. 请输入一个网址:www.baidu.com

    3. web server is running

    4. [root@server scripts]# ./curl.sh

    5. 请输入一个网址:www.qweqweweqweweeressd.com

    6. curl: (6) Could not resolve host: www.qweqweweqweweeressd.com

    7. 状态码12

  • 相关阅读:
    1.12 - 指令
    IDEA常用快捷键总结(Windows)
    网申线上测评,要不要找人代做在线测评?
    转载--关闭onenote2013 /中点击超链接(指向本地文件夹)后出现的安全声明 / Microsoft onenote2021 安全声明关闭
    五种I/O模型
    Python 导入Excel三维坐标数据 生成三维曲面地形图(体) 5-2、线条平滑曲面且可通过面观察柱体变化(二)
    Linux学习——exec函数族和守护进程
    【Java】Spring Boot常用注解
    Kubernetes部署
    【MySQL数据库】一约束
  • 原文地址:https://blog.csdn.net/m0_63636799/article/details/134016310