获取shell脚本里面从PHP脚本退出状态
问题描述:
我有一个调用一些PHP脚本这样一个bash shell脚本。
I have a bash shell script that calls a few PHP scripts like this.
#!/bin/bash
php -f somescript.php
php -f anotherscript.php
我要编写基于这些脚本的结果,错误日志和/或活动报告。
I want to compose an error log and/or an activity report based on the results of those scripts.
有什么办法,我可以得到的PHP脚本中的shell脚本的退出状态?
Is there any way I can get the exit status of the php script in the shell script?
我既可以使用整数退出状态或字符串的邮件。
I could either use integer exit statuses or string messages.
答
您可以轻松地使用的反引号的操作器锁扣的输出,并获得在最后一个命令的退出code 使用的 $ 的:
You can easily catch the output using the backtick operator, and get the exit code of the last command by using $?:
#!/bin/bash
output=`php -f somescript.php`
exitcode=$?
anotheroutput=`php -f anotherscript.php`
anotherexitcode=$?