第六次作业

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

创建jiancha.sh文件 

#!/bin/bash
############################################################### 
# File Name: jiancha.sh 
# Version:V1.0 
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx1 
# Created Time : 2023-05-21 19:48:06 
# Description:
############################################################## 
mb=`df -m /| awk 'NR==2{print $4}' 
gb=$[mb/1024]
if [ "$gb" -lt 20 ] 
then
 echo "您最近的磁盘空间已经小于20G,请及时查看!"" mail -s "WORNING!" rootalocalhost 

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

创建一个shell脚本写入

#!/bin/bash
############################################################### 
# File Name: jianchal.sh
# Version: V1.0
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx/ 
# Created Time : 2023-05-21 19:55:45 
# Description:
##############################################################
rpm http=`rpm -qa httpd wC -l' 
if [ $rpm http -ge 1 ] 
then
    systemctl start httpd;
else
    yum install -y httpd; 
    systemctl start httpd;
fi
rpm firewall=`rpm -qa firewalld |wc -l' 
if [ $rpm firewall -ge 1 ] 
then
    systemctl start firewalld;
    firewall-cmd --add-service=http --permanent;
else
    yum install -y firewalld; 
    systemctl start firewalld;
    firewall-cmd --add-service=http --permanent;
fi
ps ef= ps -ef l! grep "httpd" | wc -l’
port web=`ss -lntup | grep -w"80"| wc -l’ if [ $ps ef -ge 2 ] && [ $port web -ge 2 ] 
then
    echo"web服务已运行!"
else
    echo "稍后为您开启web服务!" 
    systemctl start httpd;
fi 

3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
1.将错误输出输出到/dev/null

具体命令如下:

#!/bin/bash
##############################################################
# File Name: jiancha2.sh
# Version: V1.0
# Author: xx
# Email:xx@163.com
# Organization:http://www.xx.com/xx/
# Created Time : 2023-05-21 19:58:37
# Description:
############################################################## 
curl 192.168.233.128 > /dev/null 2>&1 
if [ $? -eq θ ] 
then
    echo "web server is running!"
else
    exit 12
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值