RHCE(五)

目录

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

1.创建脚本test1.sh

2.下载邮件服务并执行

3.测试

4.做计划任务

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

1.安装httpd

2.创建脚本test2

3.测试

4.查看端口号,修改test2脚本

5.测试

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

1.编写脚本test3.sh

2.测试


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

1.创建脚本test1.sh

[root@server ~]# vim test1.sh
#!/bin/bash
free_mb=$(free -m | grep Mem | tr -s " " | cut -d " " -f4 )
if [[  $free_mb -lt 20480 ]]
then
        echo "warning: The computer has $free_gb G of memory left ,Less than 20G" | mail -s "warning" root
else
        echo " warning: The computer has $free_gb G ,It is enough"
fi

2.下载邮件服务并执行

[root@server ~]# yum install postfix -y
[root@server ~]# yum install s-nail -y
[root@server ~]# systemctl start postfix.service   #重启服务
 

3.测试

4.做计划任务

[root@server ~]# vim /etc/crontab 

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

1.安装httpd

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

2.创建脚本test2

[root@server ~]# vim test2.sh
#!/bin/bash
num=$(ps -ef | grep httpd | grep -v grep | wc -l)
if [ $num -ge 1 ]
then    
        echo "httpd is running"
else    
        systemctl restart httpd
        systemctl stop firewalld
fi      
 

3.测试

[root@server ~]# systemctl stop httpd 
[root@server ~]# sh test2.sh  
[root@server ~]# sh test2.sh  
httpd is running

4.查看端口号,修改test2脚本

[root@server ~]# vim test2.sh
 
#!/bin/bash
 
num=$(ss -lntup  |  grep  80  | wc  -l)
if [ $num -ge 1 ]
then
        echo "httpd is running"
else
        systemctl restart httpd
        systemctl stop firewalld
fi
 

5.测试

[root@server ~]# systemctl stop httpd 
[root@server ~]# sh test2.sh  
[root@server ~]# sh test2.sh  
httpd is running

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

1.编写脚本test3.sh

[root@server ~]# vim test3.sh 
#!/bin/bash
curl -s 192.168.183.128 > /dev/null
if [[  $? = 0 ]]
then
        echo " web server is running"
else
        exit 12
fi

2.测试

[root@server ~]# sh test3.sh 
[root@server ~]# sh test3.sh 
[root@server ~]# echo $?
12

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nemophilistf.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值