[英]Install nginx web server using shell script
我想自动安装 nginx web 服务,如果 nginx 已经存在,它将安装在其他位置,例如:/usr/local/nginx。
#!/bin/bash
echo "Beginning installation of nginx web server"
if ! which nginx > /dev/null 2>&1; then
echo "Nginx is not installed"
else
echo "Installing nginx"
yum install nginx -y
#check if nginx services are up
service nginx start
fi
我是 shell 脚本的新手并尝试了上述方法,但是我无法在 else 块中执行命令。 帮助将不胜感激。
我想我明白你想做什么,但你代码中的逻辑不是最好的,所以这里是我的第一个 bash 脚本中的一个片段,我做了类似的事情:
read INP
if [ $INP -eq 1 ]
then
if command -v nginx
then
systemctl status nginx
back
else
error
read INP
if [ $INP == y ]
then
sudo apt install nginx
else
back
fi
fi
fi
顺便说一句,这是基于 Debian 的发行版,因此您可以将 apt 更改为 yum、pacman 等 package 管理器。 需要说明的是,back 和 error 是我创建的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.