小编Gol*_*129的帖子

发送预期脚本错误:执行时 Spawn id exp4 未打开

我正在尝试运行此脚本,但在修改时出现不同的错误。这是代码和输出。请帮忙。

在帖子末尾更新调试信息

    #!/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
Run Code Online (Sandbox Code Playgroud)

输出是这样的:

    goldberg188@Test-Server ~$ ./test.sh "sudo cat /etc/hosts" …
Run Code Online (Sandbox Code Playgroud)

linux unix shell bash expect

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

bash ×1

expect ×1

linux ×1

shell ×1

unix ×1