Reputation: 99
I am trying to write a script to toggle HAproxy to reroute a user to a maintenance page if a service is down. Here is the part I am having trouble with:
if [ "$idIsValid" = "false" ]; then
if [ "$(cat isUp)" = "true" ]; then
echo "Site is down! Routing to maintenance page."
echo false > isUp
mv haproxy.cfg haproxy.cfg.temp
mv haproxy.cfg.other haproxy.cfg
mv haproxy.cfg.temp haproxy.cfg.other
#restart haproxy
service haproxy restart
echo "Restarting HAproxy"
elif [ "$(cat isUp)" = "false" ]; then
#do nothing since it has already changed
echo "Nothing to do; service is still down."
else
#notify me that isUp is set to something other than true or false, or something else is wrong.
fi
fi
When I run this, I get the error:
status-check.sh: Syntax error: "fi" unexpected
This error is pointing to the nested fi on that second to last line. I am having trouble finding the syntax error here. Please assist! Thank you.
Upvotes: 2
Views: 731
Reputation: 909
It's because there are no commands in the last else
block. If you either remove this block or put a command in there (not a comment) you won't get a syntax error.
Upvotes: 1