I have a bash script that's make some operation on nginx's virtualhosts. I would like to know how to catch error if nginx not reloading correctly (nginx reload
).
I think to use nginx -t
but i don't know to intercept error in a bash script.
I have a bash script that's make some operation on nginx's virtualhosts. I would like to know how to catch error if nginx not reloading correctly (nginx reload
).
I think to use nginx -t
but i don't know to intercept error in a bash script.
Why do you want to make changes and then direct reload Nginx ? It can cause Nginx to stop working.
A better process would be to make changes -> do a configtest -> if configtest == ok -> reload nginx.
You may want to try something like:
#!/bin/sh
#...your script
nginx -t
if [ "$?" != "0" ]; then
echo "Error!"
exit 1
else
echo "All good"
fi