I want to automate the installation of nginx web service in such a way that if nginx is already present it will get installed at other location ex: /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
I am new to shell script and tried above approach, however I am unable to execute command in else block.
Help will be really appreciated.
2
Answers
I think i understand what you wanted to do but logic in you code is not the best, so here is snip from one of my first bash scripts where i did something similar:
Btw this is for Debian based distros, so you can change apt for yum, pacman, etc. package manager. And just to be clear, back and error are functions i created.
Check this out