【发布时间】:2017-03-28 07:28:49
【问题描述】:
我正在使用 shell_exec 从 PHP 执行一个 shell 脚本,如下所示:
$output = shell_exec('./intnacstat.sh "'.$ip.'" 2>&1');
intnacstat.sh 结果是:
interface GigabitEthernet0/8
description ISE dot1x Port
switchport access vlan 70
switchport trunk encapsulation dot1q
switchport trunk native vlan 70
switchport trunk allowed vlan 256
switchport mode trunk
authentication event fail action next-method
authentication host-mode multi-host
authentication open
authentication order dot1x mab
authentication priority dot1x mab
authentication port-control auto
authentication periodic
authentication timer reauthenticate server
authentication timer inactivity server
authentication violation restrict
mab
所以每个命令都在单独的行上。
但是当我在 PHP 上回显 $output 时,一切都在一行中, 基本不可读:
"show run interface G0/8 Building configuration... Current configuration : 767 bytes ! interface GigabitEthernet0/8 description ISE dot1x Port switchport access vlan 70 switchport trunk encapsulation dot1q switchport trunk native vlan 70 switchport trunk allowed vlan 256 switchport mode trunk authentication event fail action next-method authentication host-mode multi-host authentication open authentication order dot1x mab authentication priority dot1x mab authentication port-control auto authentication period authentication timer reauthenticate server authentication timer inactivity server authentication
谁能告诉我如何回显 $output 以在命令末尾添加线刹车。 或者任何其他可以做到这一点的方式。
【问题讨论】:
-
intnacstat.sh result is:你的意思是结果还是内容? -
如果我从 cli 运行 ./intnacstat.sh 我得到了 root@netdisco:/var/www/html# ./intnacstat.sh 10.97.31.130 show run interface G0/8 Building configuration。 .. 当前配置:767 字节! interface GigabitEthernet0/8 description ISE dot1x Port switchport access vlan 70
-
如果我在 intnacstat.sh 的结果中执行 cat -E root@netdisco:/var/www/html# cat -E stat.txt $how run interface G0/8 $uilding configuration。 .. $ $urrent configuration : 767 bytes $ $nterface GigabitEthernet0/8 $description ISE dot1x Port $switchport access vlan 70 $switchport trunk encapsulation dot1q 行尾没有换行符。所以可能期望脚本不行。
-
像你这样的外部软件很难维护,但这不是 shell_exec 的正常行为,请尝试使用 exec 代替并检查
标签: php shell-exec