使用shell自动化部署网站脚本
[root@server ~]# ls /
afs boot etc lib lost+found mnt proc run srv test usr
bin dev home lib64 media opt root sbin sys tmp var
[root@server ~]# vim test.sh
#!/bin/bash
#使用nginx搭建test网站
num=$(ps -ef | grep nginx | grep -v grep | wc -l) #根据进程判断nignx是否安装启用
if ((num==0))
then
echo "nginx正在安装,请等待......"
yum install nginx -y &> /dev/null
echo "正在部署网站,请等待......"
sed -i '42s/\/usr\/share\/nginx\/html/\/test/g' /etc/nginx/nginx.conf
systemctl start nginx
curl 192.168.160.137 &> /dev/null
echo "网站搭建成功,请在Windows的浏览器输入IP地址进行查看,脚本执行结束。"
else
sed -i '42s/\/usr\/share\/nginx\/html/\/test/g' /etc/nginx/nginx.conf
systemctl restart nginx
curl 192.168.160.137 &> /dev/null
echo "网站搭建成功,请在Windows的浏览器输入IP地址进行查看,脚本执行结束。"
fi