gpt4 book ai didi

Linux Expect 退出前等待

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:45 28 4
gpt4 key购买 nike

#!/usr/bin/expect
# Test expect script to telnet.

spawn telnet 192.168.1.1
expect "Username: "
send "adminpldt\r"
expect "Password: "
send "password\r"
expect "$"
send "show lan\r"
send "show\r"
expect eof
close
# end of expect script.

这就是问题所在,当我运行这段代码时,它显示了正确的输出。但是之后它不会退出,就像等待输入一样。就像超时一样。但是如果我删除这条线“期待 EOF”。它立即终止。有人能帮我吗?我刚开始使用 Linux 脚本,并且搜索了 stackoverflow 上的每个主题

编辑:问题已解决

>     >     #!/usr/bin/expect
> > # Test expect script to telnet.
> >
> > spawn telnet 192.168.1.1
> > expect "Username: "
> > send "adminpldt\r"
> > expect "Password: "
> > send "password\r"
> > expect "$"
> > send "sh\r"
> > send "config\r"
> > send "macc interface lan1 [lindex $argv 0]\r"
> > send "macc interface lan2 [lindex $argv 0]\r"
> > send "macc interface lan3 [lindex $argv 0]\r"
> > send "macc interface lan4 [lindex $argv 0]\r"
> > send "macc interface wlan [lindex $argv 0]\r"
> > send "exit\r"
> > send "exit\r"
> > expect eof
> > # end of expect script.

我明白了。 eof 是它返回 bash 的时候。当我完全掌握我的路由器配置时,我才意识到这一点。

最佳答案

问题解决了

#!/usr/bin/expect
# Test expect script to telnet.

spawn telnet 192.168.1.1
expect "Username: "
send "adminpldt\r"
expect "Password: "
send "password\r"
expect "$"
send "sh\r"
send "config\r"
send "macc interface lan1 [lindex $argv 0]\r"
send "macc interface lan2 [lindex $argv 0]\r"
send "macc interface lan3 [lindex $argv 0]\r"
send "macc interface lan4 [lindex $argv 0]\r"
send "macc interface wlan [lindex $argv 0]\r"
send "exit\r"
send "exit\r"
expect eof
# end of expect script.

我明白了。 eof 是它返回 bash 的时候。当我完全掌握我的路由器配置时,我才意识到这一点。

关于Linux Expect 退出前等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343223/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com