Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Expect脚本在foreach循环中失败_Loops_Ssh_Foreach_Expect - Fatal编程技术网

Loops Expect脚本在foreach循环中失败

Loops Expect脚本在foreach循环中失败,loops,ssh,foreach,expect,Loops,Ssh,Foreach,Expect,我有一个expect脚本,它在一个包含主机列表的文件中循环,ssh进入每个主机,sudo进入根目录,并运行id。问题是它永远不会返回到源服务器外壳。它试图从它已使用ssh连接到的主机上运行,从而弄乱了逻辑 set file [open "hosts.test"] set hosts [split [read -nonewline $file] "\n"] close $file foreach host $hosts { puts $host spawn ssh -q -o S

我有一个expect脚本,它在一个包含主机列表的文件中循环,ssh进入每个主机,sudo进入根目录,并运行id。问题是它永远不会返回到源服务器外壳。它试图从它已使用ssh连接到的主机上运行,从而弄乱了逻辑

set file [open "hosts.test"]
set hosts [split [read -nonewline $file] "\n"]
close $file

foreach host $hosts {
    puts $host
    spawn ssh -q -o StrictHostKeyChecking=no  [lindex $argv 0]@$host
    expect "Password: "
    send "[lindex $argv 1]\r"
    expect -re "(>|#) "
    send "sudo su -\r"
    expect "Enter YOUR password: "
    send "[lindex $argv 1]\r"
    expect -re "(>|#) "
    send "id\r"
    expect -re "(>|#) "
    send "exit\r"
    expect -re "(>|#) "
    send "logout\r"
    close $spawn_id
 }
以下是错误:

send: sending "logout\r" to { exp4 }
server.blah.com
spawn ssh -q -o StrictHostKeyChecking=no user@server
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {21856}

expect: does "" (spawn_id exp5) match glob pattern "Password: "? no
Password:
expect: does "Password: " (spawn_id exp5) match glob pattern "Password: "? yes
expect: set expect_out(0,string) "Password: "
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) "Password: "
send: sending "passwordhere\r" to { exp5 }
Gate keeper glob pattern for '(>|#) ' is ''. Not usable, disabling the performance booster.

expect: does "" (spawn_id exp5) match regular expression "(>|#) "? (No Gate, RE only) gate=yes re=no


expect: does "\r\n" (spawn_id exp5) match regular expression "(>|#) "? (No Gate, RE only) gate=yes re=no
Password:
expect: does "\r\nPassword: " (spawn_id exp5) match regular expression "(>|#) "? (No Gate, RE only) gate=yes re=no
expect: timed out
send: sending "sudo su -\r" to { exp5 }

expect: does "\r\nPassword: " (spawn_id exp5) match glob pattern "Enter YOUR password: "? no


expect: does "\r\nPassword: \r\n" (spawn_id exp5) match glob pattern "Enter YOUR password: "? no
Password:
expect: does "\r\nPassword: \r\nPassword: " (spawn_id exp5) match glob pattern "Enter YOUR password: "? no
expect: timed out
send: sending "passwordhere\r" to { exp5 }
Gate keeper glob pattern for '(>|#) ' is ''. Not usable, disabling the performance booster.

expect: does "\r\nPassword: \r\nPassword: " (spawn_id exp5) match regular expression "(>|#) "? (No Gate, RE only) gate=yes re=no


expect: does "\r\nPassword: \r\nPassword: \r\n" (spawn_id exp5) match regular expression "(>|#) "? (No Gate, RE only) gate=yes re=no
expect: read eof
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) "\r\nPassword: \r\nPassword: \r\n"
send: sending "id\r" to { exp5 send: spawn id exp5 not open
while executing
"send "id\r""
("foreach" body line 11)
invoked from within
"foreach host $hosts {
    puts $host
    spawn ssh -q -o StrictHostKeyChecking=no  [lindex $argv 0]@$host
    expect "Password: "
    send "[lindex $argv 1]\r"
    e..."
(file "./bootstrap.exp" line 19)

看起来你输入了错误的登录密码。我在这里更改了明文密码。这不是问题,问题是它永远不会返回到源服务器。它尝试从它登录的第一台服务器再次生成,因此它永远不会返回到它期望在脚本中使用的原始shell。查看调试输出,我看到相同的密码:prompt repeated。我的结论是密码没有正确发送。您是否看到所有超时消息?