bash期待***

时间:2016-10-13 11:56:53

标签: bash expect

我有一个非常简单的期望脚本,可通过Cisco路由器连接到思科无线局域网控制器。 我的问题是,在一些命令期望突然停止而没有完成所有句子并且没有任何错误。 我认为问题出在*来自密码,但我不确定。 那是我的剧本

#!/usr/bin/expect
set timeout 10

spawn telnet X.Y.Z.W

expect "User Access Verification"
expect "Username:"
send "admin\r"
expect "Password:"
send "PASSWORD\r"
expect "Router#"
send "telnet WLC_IP\r"
expect "(Cisco Controller)"
expect "User:"
send "admin\r"
expect "Password:"
send "PASSWORD\r"
expect "Cisco Controller"
send " config paging disable\r"
expect "Cisco Controller"
send " show ap auto-rf 802.11b AP-NAME\r"
expect "Cisco Controller"
send "logout\r";

这是运行后的输出,

spawn telnet X.Y.Z.W
Trying X.Y.Z.W...
Connected to X.Y.Z.W.
Escape character is '^]'.


User Access Verification

Username: admin
Password:

Router#telnet WLC_IP
Trying WLC_IP ... Open

(Cisco Controller)
User: admin
Password:**********
(Cisco Controller) >?

clear          Clear selected configuration elements.
config         Configure switch options and settings.
cping          Send capwap echo packets to a specified mobility peer IP address.
debug          Manages system debug options.
eping          Send Ethernet-over-IP echo packets to a specified mobility peer IP address.
grep           Print lines matching a pattern.
help           Help
license        Manage Software License
linktest       Perform a link test to a specified MAC address.
logout         Exit this session. Any unsaved changes are lost.
mping          Send Mobility echo packets to a specified mobility peer IP address.
ping           Send ICMP echo packets to a specified IP address.
reset          Reset options.
save           Save switch configurations.
show           Display switch options and settings.
test           Test trigger commands
transfer       Transfer a file to or from the switch.

(Cisco Controller) >config paging disable


(Cisco Controller) >[root@mailman scripts]#

另外,有一个“?”密码后,我不知道为什么。

有什么想法吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

在我的脚本末尾设置expect eof后效果很好!我不确定它是否是强制性的但对我有效。

谢谢!