shell脚本作业

题目:通过shell脚本分析部署nginx网络服务

1.接收用户部署的服务名称

2.判断服务是否安装

 已安装;自定义网站配置路径为/www;并创建共享目录和网页文件;重启服务

 没有安装;安装对应的软件包

3.测试

判断服务是否成功运行;

 已运行,访问网站

 未运行,提示服务未启动,并显示自定义的配置文件内容

 4.以上配置没有问题,请邮件告知我,并将脚本代码(代码文件)邮件发送我

我的邮箱账号:lxx1065372838@163.com

一、邮箱配置 

[root@localhost redhat]# systemctl stop firewalld
[root@localhost redhat]# setenforce 0
[root@localhost redhat]# mount /dev/sr0 /mnt
[root@localhost redhat]# dnf install  s-nail -y
[root@localhost redhat]# tail -5 /etc/s-nail.rc
set from=m17384403619@163.com
set smtp=smtp.163.com
set smtp-auth-user=m17384403619@163.com
set smtp-auth-password=DSrcqtw8CgKSLeQJ
set smtp-auth=login

二、 

[root@localhost redhat]# vim rly.sh
[root@localhost redhat]# cat rly.sh
#!/bin/bash
1.接收用户部署的服务名称                                                                                 
read -p "请输入要部署的服务名称:" service_name      
2.判断服务是否安装
if rpm -q $service_name &> /dev/null;then
	echo "服务已安装"
        config_path="/www"   
	mkdir -p $config_path 
	echo "hello,this is a test page" > $config_path/index/html 
	systemctl restart $service_name    
else
	echo "服务未安装。开始安装"
	yum install -y $service_name     
fi




if systemctl is-active  $service_name;then  
	echo "服务正在运行,访问网站:http://localhost"
	curl http://localhost           
else
	echo "服务未启动"
	cat $config_path/index.html   
fi



   
if systemctl is-active  $service_name;then    
	echo "nginx服务已成功部署并运行" | mail -s "rly"  lxx1065372838@163.com     
        mail -s "rly的nginx脚本"    lxx1065372838@163.com  < $0                                
fi
[root@localhost ~]# bash rly.sh
请输入要部署的服务名称:nginx
服务已安装
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
failed
服务未启动
hello,this is a test page
failed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值