我正在尝试编写一个expect脚本来自动化telnet。这是我目前的代码。
#!/usr/bin/expect
# Test expect script to telnet.
spawn telnet 10.62.136.252
expect "foobox login:"
send "foo1\r"
expect "Password:"
send "foo2\r"
send "echo HELLO WORLD\r"
# end of expect script.
基本上,我想做的是telnet到以下IP地址,然后回显HELLO WORLD。然而,在尝试telnet之后,脚本似乎失败了...我不确定它能否接受登录和密码输入,但它没有回显HELLO WORLD。相反,我只得到这个输出:
cheungj@sfgpws30:~/justin> ./hpuxrama
spawn telnet 10.62.136.252
Trying 10.62.136.252...
Connected to 10.62.136.252.
Escape character is '^]'.
Welcome to openSUSE 11.1 - Kernel 2.6.27.7-9-pae (7).
foobox login: foo1
Password: foo2~/justin>