我有一个 index.php,如下所示。
<?php
$v = passthru("expect ./script2.exp qbadmin password hostname 'root_password' 6969") > &1;
echo "==========" . $v;
?>
我的期望脚本如下,
#!/usr/bin/expect
set username [lindex $argv 0]
set pass [lindex $argv 2]
set host [lindex $argv 1]
set rootpass [lindex $argv 3]
set port [lindex $argv 4]
spawn ssh -o GSSAPIAuthentication=no $username@$host -p $port
expect -timeout 3 "*(yes/no)?" { send "yes\r";exp_continue }
expect -timeout 3 "*d: "
send "$pass\n"
expect -timeout 3 "*$ "
send "su -\r"
expect -timeout 3 "*d: "
send "$rootpass\r"
expect -timeout 3 "*#"
send "ls /home\r"
interact
当我在浏览器中加载 index.php 文件时,它看起来像下面给出的。
ls /home
我的目的是在浏览器的期望脚本中显示倒数第二个命令的输出。我需要在这里做什么修改。当我单独运行期望脚本时,它会给出正确的输出。请给我建议,因为我是 php 的初学者。