我的php代码:
<?php
$output = shell_exec('/bin/f2bstatus');
echo "$output";
echo "<hr />";
echo 'Current PHP version: ' . phpversion();
?>
我的shell脚本(f2bstatus):
#!/bin/bash
echo "<div>"
echo "<h2>Fail2Ban Jail Status</h2>"
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
echo "</div>"
shell脚本的终端输出:
<div>
<h2>Fail2Ban Jail Status</h2>
Status for the jail: recidive
|- Filter
| |- Currently failed: 0
| |- Total failed: 12
| `- File list: /var/log/fail2ban.log
`- Actions
|- Currently banned: 6
|- Total banned: 6
`- Banned IP list: xxx.xxx.xxx.xxx ...
Status for the jail: sshd
|- Filter
| |- Currently failed: 1
| |- Total failed: 15
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 0
|- Total banned: 6
`- Banned IP list:
</div>
php输出(从视图源):
<div>
<h2>Fail2Ban Jail Status</h2>
</div>
<hr />Current PHP version: 7.1.24
据我所知,似乎for循环正在执行,但fail2bain-client脚本未由php运行(或未通过?)
我也尝试使用反引号运算符代替shell_exec,但结果相同
我还尝试了其他系统命令(例如ls),并且效果很好
在fail2ban-client手册页中,它提到“客户端本身分叉一次”-这与正在发生的事情有什么关系吗?
想法/建议/解释?
tyia,
chris