Want to write an automatic script
Test the generated configuration file first
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/test.conf
If the test is successful, overwrite nginx.conf. If it is not successful, an error will be returned.
However, I don’t know how to obtain the information after executing the test instructions. The instructions are all executed successfully
bash,
$?
is used to get the return value of the previous command. 0 is normal, and other values are abnormal.If you need to get the command output, you can do it as follows:
The function of
2>&1
is to redirect standard error to standard output