-1

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.

Davide
  • 101
  • 2

2 Answers2

1

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.

termcap
  • 93
  • 1
  • 7
0

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
David B.
  • 466
  • 1
  • 3
  • 12