쉘을 사용하여 nginx에서 테스트 결과를 얻는 방법
習慣沉默
習慣沉默 2017-05-16 17:15:34
0
1
674

자동 스크립트를 작성하고 싶어요
생성된 구성 파일을 먼저 테스트해보세요

으아아아

테스트가 성공하면 nginx.conf를 덮어쓰세요. 실패하면 오류가 반환됩니다

그런데 테스트 지침을 실행한 후 정보를 어떻게 얻는지 모르겠습니다. 지침이 모두 성공적으로 실행되었습니다.

習慣沉默
習慣沉默

모든 응답(1)
黄舟

으아악

Bash에서는 이전 명령의 반환 값을 가져오는 데 $?를 사용합니다. 0은 정상이고 다른 값은 비정상입니다. $? 用来获取上一条命令的返回值,0 为正常,其他值为异常。

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

[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

其中2>&1

명령 출력을 가져와야 하는 경우 다음과 같이 수행할 수 있습니다. 🎜 으아악 🎜2>&1의 기능은 표준 오류를 표준 출력으로 리디렉션하는 것입니다🎜
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!