Erwarten Skriptfehler senden: Spawn id exp4 nicht öffnen während der Ausführung

Ich versuche, führen Sie dieses Skript aber unterschiedlichen Fehler, die bei änderungen. Hier ist der code und die Ausgabe. Bitte helfen Sie.

Updates am Ende des Beitrags mit debug-info

    #!/bin/bash
    (( $# != 1 )) && { echo >&2 "Usage: $0 \"[COMMAND]\""; exit 1; }
    servers_addresses=(10.10.10.10 )
    for server_address in ${servers_addresses[@]}; do
    expect <<EOF
    spawn ssh -t root@$server_address "$*"
    expect -timeout 2 "Are you sure you want to continue connecting (yes/no)?" { send "yes\n" }
    expect "s password:" { send "Correct_Password\n" }
    expect "s password:" { send "Wrong_Password_22222\n" }
    expect "s password:" { send "Wrong_Password_33333\n" }
    expect eof
    EOF
    done

Und die Ausgabe ist wie:

    goldberg188@Test-Server ~$ ./test.sh "sudo cat /etc/hosts"
    spawn ssh -t root@10.10.10.10 sudo cat /etc/hosts
    root@10.10.10.10's password:
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    10.10.10.10             TEST-004 localhost.localdomain localhost
    ::1             localhost6.localdomain6 localhost6
    Connection to 10.10.10.10 closed.
    expect: spawn id exp4 not open
        while executing
    "expect "s password:" { send "Wrong_Password_33333\n" }"

Wenn ich ändern wie dieser, dann ist die Ausgabe wäre etwas anders

    expect "s password:" { send "Wrong_Password_11111\n" }
    expect "s password:" { send "Correct_Password\n" }
    expect "s password:" { send "Wrong_Password_33333\n" }

    goldberg188@Test-Server ~$ ./test.sh "sudo cat /etc/hosts"
    spawn ssh -t root@10.10.10.10 sudo cat /etc/hosts
    root@10.10.10.10's password:
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    10.10.10.10             TEST-004 localhost.localdomain localhost
    ::1             localhost6.localdomain6 localhost6
    Connection to 10.10.10.10 closed.
    expect: spawn id exp4 not open
        while executing
    "expect eof"

Und wenn das korrekte Passwort in der Dritten Zeile dann keine Fehler überhaupt. Funktioniert gut auf diese ein.

    expect "s password:" { send "Wrong_Password_11111\n" }
    expect "s password:" { send "Wrong_Password_22222\n" }
    expect "s password:" { send "Correct_Password\n" }


    goldberg188@Test-Server ~$ ./test.sh "sudo cat /etc/hosts"
    spawn ssh -t root@10.10.10.10 sudo cat /etc/hosts
    root@10.10.10.10's password:
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    10.10.10.10             TEST-004 localhost.localdomain localhost
    ::1             localhost6.localdomain6 localhost6
    Connection to 10.10.10.10 closed.

Update: Debug-info - Geändert

    exp_internal 1
    expect "s password:" { send "Wrong_Password_11111\n" }
    expect "s password:" { send "Correct_Password\n" }
    expect "s password:" { send "Wrong_Password_33333\n" }

Ausgabe:

    goldberg188@Test-Server ~$ ./test.sh "sudo cat /etc/host"
    spawn ssh -t root@10.10.10.10 sudo cat /etc/host
    root@10.10.10.10's password:
    expect: does "[email protected]'s password: " (spawn_id exp4) match glob pattern "s password:"? yes
    expect: set expect_out(0,string) "s password:"
    expect: set expect_out(spawn_id) "exp4"
    expect: set expect_out(buffer) "root@10.10.10.10's password:"
    send: sending "Wrong_Password_11111\n" to { exp4 }

    expect: does " " (spawn_id exp4) match glob pattern "s password:"? no


    expect: does " \r\n" (spawn_id exp4) match glob pattern "s password:"? no
    Permission denied, please try again.
    [email protected]'s password:
    expect: does " \r\nPermission denied, please try again.\r\r\[email protected]'s password: " (spawn_id exp4) match glob pattern "s password:"? yes
    expect: set expect_out(0,string) "s password:"
    expect: set expect_out(spawn_id) "exp4"
    expect: set expect_out(buffer) " \r\nPermission denied, please try again.\r\r\[email protected]'s password:"
    send: sending "Correct_Password\n" to { exp4 }

    expect: does " " (spawn_id exp4) match glob pattern "s password:"? no


    expect: does " \r\n" (spawn_id exp4) match glob pattern "s password:"? no
    cat: /etc/host: No such file or directory
    Connection to 10.10.10.10 closed.

    expect: does " \r\ncat: /etc/host: No such file or directory\r\r\nConnection to 10.10.10.10 closed.\r\r\n" (spawn_id exp4) match glob pattern "s password:"? no
    expect: read eof
    expect: set expect_out(spawn_id) "exp4"
    expect: set expect_out(buffer) " \r\ncat: /etc/host: No such file or directory\r\r\nConnection to 10.10.10.10 closed.\r\r\n"
    expect: spawn id exp4 not open
        while executing
    "expect eof"
Hinweis: die gleiche Frage auf serverfault: serverfault.com/q/642129/30957

InformationsquelleAutor Diplayed name | 2014-11-05

Schreibe einen Kommentar