开发者

Why does Expect dump commands without execution?

I'm learning Expect, and I've noticed that my Expect scripts sometimes reach a point where they begin to dump commands without executing them. What causes this to happen? I've scraped Google and a couple Expect tutorials, but the keywords related to this issue are not filtering an answer. Any guidance or references are greatly appreciated.

Example Expect Script:

#!/usr/bin/env expect
set ip [lindex $argv 0]
spawn ssh root@$ip /dir/run.sh
expect {
    "password:" {
        send "secret_password\n"
    }

    "No route to host" {
        spawn开发者_开发百科 echo "This gets dumped, not executed."
    }
}

Output:

$ ./ex.exp 192.168.0.22
spawn ssh root@192.168.0.22 /dir/run.sh
ssh: connect to host 192.168.0.22 port 22: No route to host
spawn echo This gets dumped, not executed.


Echo is not a command, so maybe it displays instead since it doesn't tell it to do anything.

Try this instead:

#!/usr/bin/env expect
set ip [lindex $argv 0]
spawn ssh root@$ip /dir/run.sh
expect {
    "password:" {
        send "secret_password\n"
    }

    "No route to host" {
        puts stdout "Host not reachable."
    }
    "Connection refused" {
        puts stdout "Host not accepting ssh."
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜