您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Web开发 >> Nginx+Nodejs nginx如何用shell获取测试结果

Nginx+Nodejs nginx如何用shell获取测试结果

来源:网络整理     时间:2016/8/18 2:26:37     关键词:Nginx+Nodejs

关于网友提出的“Nginx+Nodejs nginx如何用shell获取测试结果”问题疑问,本网通过在网上对“Nginx+Nodejs nginx如何用shell获取测试结果”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:Nginx+Nodejs nginx如何用shell获取测试结果
描述:

想写一个自动脚本
先测试生成的配置文件

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/test.conf

如果测试成功就覆盖nginx.conf 不成功就返回错误

然而不知道如何获取执行测试指令之后的信息 指令都是执行成功


解决方案1:

[root@arbiter nginx]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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
[root@arbiter nginx]# echo $?
0

[root@arbiter nginx]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/mime.types
nginx: [emerg] "types" directive is not allowed here in /usr/local/nginx/conf/mime.types:2
nginx: configuration file /usr/local/nginx/conf/mime.types test failed
[root@arbiter nginx]# echo $?
1

bash 中 $? 用来获取上一条命令的返回值,0 为正常,其他值为异常。

如果需要获取命令输出,可以按一下方式操作:

[root@arbiter nginx]# a="`/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/mime.types 2>&1`"
[root@arbiter nginx]# echo $a
nginx: [emerg] "types" directive is not allowed here in /usr/local/nginx/conf/mime.types:2 nginx: configuration file /usr/local/nginx/conf/mime.types test failed

其中2>&1的作用是将标准错误重定向到标准输出


以上介绍了“Nginx+Nodejs nginx如何用shell获取测试结果”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3358325.html

Nginx+Nodejs相关图片

Nginx+Nodejs相关文章