无法从php

时间:2016-05-18 09:40:36

标签: php powershell ssh shell-exec cisco

我使用以下Powershell脚本来获取在cisco设备上运行的show run命令:

getconfig.ps1

$ErrorActionPreference ="Inquire"
Import-Module SSH-Sessions
$time ="$(get-date -f yyyy-MM-dd)"
$filename ="config"
$ext =".txt"
$filepath ="temp\"
$d1 ="x.x.x.x"
$u1 ="user"
$p1 ="password"
New-SshSession $d1 -Username $u1 -Password "$p1"
$c1 ="show run"
$Results = Invoke-Sshcommand -InvokeOnAll -Command "$c1" | Out-File "$filepath$filename-$time$ext"
Remove-SshSession -RemoveAll
exit

当我通过右键单击/运行PowerShell手动运行此脚本时,这很好。当我尝试通过PHP运行此脚本时出现问题。

的index.php

<?php
$output = shell_exec('powershell C:\wamp\www\getconf\script\getconfig.ps1');
echo "<pre>$output</pre>";
?>

index.php永远加载,永远不会给我输出,也永远不会创建结果文件。

我试图运行另一个脚本,例如 test.ps1 ,它只是创建一个目录并且工作正常;我得到了输出,我的目录就被创建了。

我的powershell脚本有效。

PHP和我的PowerShell脚本之间的链接有效。

我不明白问题出在哪里。

1 个答案:

答案 0 :(得分:0)

正如jisaak评论的那样,问题是我的网络服务器无法到达目的地目录。

通过正确地对路径进行硬编码,问题已得到解决。

相关问题