Use o status de saída. A partir do mangage nginx:
Exit status is 0 on success, or 1 if the command fails.
e do link :
$? reads the exit status of the last command executed.
Um exemplo:
[root@d ~]# /usr/local/nginx/sbin/nginx -t;echo $?
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
0
[root@d ~]# echo whatever > /usr/local/nginx/nonsense.conf
[root@d ~]# /usr/local/nginx/sbin/nginx -t -c nonsense.conf;echo $?
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /usr/local/nginx/nonsense.conf:2
nginx: configuration file /usr/local/nginx/nonsense.conf test failed
1
Um exemplo de script:
#!/bin/bash
/usr/local/nginx/sbin/nginx -t 2>/dev/null > /dev/null
if [[ $? == 0 ]]; then
echo "success"
# do things on success
else
echo "fail"
# do whatever on fail
fi