码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • shell


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

    二、判断web服务是否运行

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


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

            1.服务端和客户端安装mailx和postfix

    1. [root@A ~]# yum install postfix -y
    2. [root@A ~]# systemctl enable postfix --now
    3. [root@B ~]# yum install sendmail -y

            2.编写脚本

    1. set from=2151208022@qq.com
    2. set smtp=smtp.qq.com
    3. set smtp-quth-user=2151208022@qq.com
    4. set smtp-auth-password=QMSWZJIRXHTVILLU
    5. set smtp-auth=login

             3.判断当前磁盘剩余空间是否由20G

    1. a=`df -m | grep -w /boot | tr -s " " " "|cut -d " " -f 4`
    2. b=`df -m | grep -w / | tr -s " " " "|cut -d " " -f 4`
    3. c=$((a+b))
    4. free=$((c/1024))
    5. if [ $free -lt 20 ]
    6. then
    7. echo 空间不足!| mail -s "内存报警!" redhat
    8. fi

           4.设置任务计划 

    1. SHELL=/bin/bash
    2. PATH=/sbin:/bin:/usr/sbin:/usr/bin
    3. MAILTO=root
    4. # For details see man 4 crontabs
    5. # Example of job definition:
    6. # .---------------- minute (0 - 59)
    7. # | .------------- hour (0 - 23)
    8. # | | .---------- day of month (1 - 31)
    9. # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
    10. # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    11. # | | | | |
    12. # * * * * * user-name command to be executed
    13. 0 0 * * * root /root/mail.sh

    二、判断web服务是否运行

            1.下载httpd包

    [root@A~]# yum install httpd -y
    

            2.编写脚本

    1. ps_httpd=`ps -ef | grep httpd | grep -v grep | wc -l`
    2. if [[ $ps_httpd > 0 ]];then
    3. echo "httpd.server is runing"
    4. else
    5. systemctl start httpd
    6. systemctl stop firewalld
    7. fi

            3.测试

    1. [root@A ~]# bash httpd.sh
    2. httpd.server is runing

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

            1.编写脚本

    1. curl -s 192.168.90.132 > /dev/null
    2. if [[ $? = 0 ]];then
    3. echo "web server is runing"
    4. else
    5. exit 10
    6. fi

            2.测试

    1. [root@A ~]# systemctl restart httpd
    2. [root@A ~]# systemctl status httpd
    3. ● httpd.service - The Apache HTTP Server
    4. Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; ven>
    5. Active: active (running) since Sun 2023-05-28 12:40:28 CST; 8s ago
    6. Docs: man:httpd.service(8)
    7. Main PID: 5895 (httpd)
    8. Status: "Started, listening on: port 80"
    9. Tasks: 213 (limit: 10756)
    10. Memory: 47.9M
    11. CPU: 82ms
    12. CGroup: /system.slice/httpd.service
    13. ├─5895 /usr/sbin/httpd -DFOREGROUND
    14. ├─5896 /usr/sbin/httpd -DFOREGROUND
    15. ├─5897 /usr/sbin/httpd -DFOREGROUND
    16. ├─5898 /usr/sbin/httpd -DFOREGROUND
    17. └─5899 /usr/sbin/httpd -DFOREGROUND
    18. 5月 28 12:40:28 server.hostname.com systemd[1]: Starting The Apache HTTP >
    19. [root@server ~]# bash web.sh
    20. web server is runing
    21. [root@server ~]# systemctl stop httpd
    22. [root@server ~]# bash web.sh
    23. [root@server ~]# echo $?
    24. 10
  • 相关阅读:
    前端ui组件库
    vscode插件开发(三)命令
    前端位运算对应的数学公式
    获取微信公众号发布内容封面图片url
    你写过的最蠢的代码是?——后端篇
    使用句法依存分析实现KBQA中的约束挂载
    [JAVAee]Spring拦截器
    葡萄糖-聚乙二醇-巯基Glucose-PEG-Alkyne|葡萄糖-聚乙二醇-生物素Glucose-PEG-Biotin
    vue2源码学习(3)-响应式原理(二)
    DTSE Tech Talk丨第3期:解密数据隔离方案,让SaaS应用开发更轻松
  • 原文地址:https://blog.csdn.net/Ztl123321/article/details/130902680
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号