当前位置: 首页 > news >正文

shell

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

二、判断web服务是否运行

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


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

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

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

        2.编写脚本

set from=2151208022@qq.com             
set smtp=smtp.qq.com                   
set smtp-quth-user=2151208022@qq.com   
set smtp-auth-password=QMSWZJIRXHTVILLU
set smtp-auth=login  

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

a=`df -m | grep -w /boot | tr -s " " " "|cut -d " " -f 4`
b=`df -m | grep -w / | tr -s " " " "|cut -d " " -f 4`
c=$((a+b))
free=$((c/1024))
if [ $free -lt 20 ]
thenecho 空间不足!| mail -s "内存报警!" redhat
fi

       4.设置任务计划 

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

二、判断web服务是否运行

        1.下载httpd包

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

        2.编写脚本

ps_httpd=`ps -ef | grep httpd | grep -v grep | wc -l`
if [[ $ps_httpd > 0 ]];thenecho "httpd.server is runing"
elsesystemctl start httpdsystemctl stop firewalld
fi                                      

        3.测试

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

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

        1.编写脚本

curl -s 192.168.90.132 > /dev/null
if [[ $? = 0 ]];thenecho "web server is runing"
elseexit 10
fi

        2.测试

[root@A ~]# systemctl restart httpd
[root@A ~]# systemctl status httpd
● httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; ven>Active: active (running) since Sun 2023-05-28 12:40:28 CST; 8s agoDocs: man:httpd.service(8)Main PID: 5895 (httpd)Status: "Started, listening on: port 80"Tasks: 213 (limit: 10756)Memory: 47.9MCPU: 82msCGroup: /system.slice/httpd.service├─5895 /usr/sbin/httpd -DFOREGROUND├─5896 /usr/sbin/httpd -DFOREGROUND├─5897 /usr/sbin/httpd -DFOREGROUND├─5898 /usr/sbin/httpd -DFOREGROUND└─5899 /usr/sbin/httpd -DFOREGROUND5月 28 12:40:28 server.hostname.com systemd[1]: Starting The Apache HTTP >
[root@server ~]# bash web.sh 
web server is runing
[root@server ~]# systemctl stop httpd
[root@server ~]# bash web.sh 
[root@server ~]# echo $?
10
http://www.lryc.cn/news/91441.html

相关文章:

  • springboot+ssm+java校园二手物品交易系统vxkyj
  • Android系统内置应用
  • CMMI实施需要准备什么:
  • 【ARM AMBA AXI 入门 1 - AXI 握手协议】
  • 详解uni-app应用生命周期函数
  • 【WebFlux】List指定bean引用对象更新后同步到List
  • 【JavaSE】Java基础语法(二十六):Collection集合
  • jmeter做接口压力测试_jmeter接口性能测试
  • 网络编程 lesson5 IO多路复用
  • 码出高效_第一章 | 有意思的二进制表示及运算
  • 测试类型(单元、集成、系统或手动测试)
  • 【笔试强训编程题】Day3.(字符串中找出连续最长的数字串 69385)和(数组中出现次数超过一半的数字 23271)
  • 学懂缓存雪崩,缓存击穿,缓存穿透仅需一篇,基于Redis讲解
  • Android 12.0SystemUI 状态栏下拉和通知栏始终居中
  • 面向过程编程和面向对象编程的区别
  • 2023年数学与人工智能国际会议——火热征稿中~
  • 格式化数字的实用命令:numfmt
  • 传统的交叉熵函数如何通过平滑处理可以适用于多标签分类任务
  • 关于Netty的一些问题
  • Java - ThreadLocal数据存储和传递方式的演变之路
  • vuex三问
  • Selenium自动化测试(基于Java)
  • 【网页布局形式----浮动】
  • 人力资源管理的本质
  • [NOIP2015 提高组] 运输计划
  • 【GreendDao 】RxQuery根据指定条件查询,完成后处理UI逻辑
  • 【C++】unordered_set 和 unordered_map 使用 | 封装
  • C++环形缓冲区设计与实现:从原理到应用的全方位解析
  • 阿里云服务器部署flask简单方法
  • 【JavaSE】Java基础语法(二十三):递归与数组的高级操作