shell第一次作业
1、判断当前磁盘剩余空间是否有20G,如果小于20G,则将报警邮件发送给管理员,每天检查一次磁盘剩余空间。
1)查看磁盘剩余空间:
# 显示内存的剩余容量
[root@server ~]# free -h | grep "Mem" | awk '{print $4}'
368Mi
# awk '{print $4}' 过滤出第4列
2)编写脚本 free.sh ,将报警邮件发送给管理员
3)加可执行权限
[root@server ~]# chmod a+rx free.sh
4)测试
2、判断web服务是否运行
(1)查看进程的方式判断该程序是否运行,
(2)通过查看端口的方式判断该程序是否运行,如果没有运行,则启动该服务并配置防火墙规则。
-
查看进程方式:
1)提前安装httpd包(yum install -y httpd)
[root@server ~]# yum install httpd -y
2)编写脚本web.sh
3) 加可执行权限
[root@server ~]# chmod a+rx web.sh
4)测试
[root@server ~]# bash web.sh
httpd service is running
查看端口方式:
1)编写脚本web2.sh
2) 加可执行权限
[root@server ~]# chmod a+rx web2.sh
3)测试
3、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
1)编写脚本web_server.sh
2)测试