Linux 退出前等待

标签 linux expect

#!/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 退出前等待,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343223/

相关文章:

linux - 来自期望文件中的文本文件的源不起作用

linux - 无法从不同的机器访问 weblogic 控制台

c - 如何在不重新编译Linux内核的情况下实现自己的系统调用?

error-handling - 捕获Expect脚本的退出代码

linux - 如何判断/dev/tty 是否是基于文本的?

ruby - 如何在 Linux 上运行 Ruby 脚本并在 TOP COMMAND 中显示脚本名称而不是 Ruby?

shell - 自动化期间在Expect Shell脚本中无法建立主机的真实性时如何忽略或传递 'Yes'

linux - TCL,预计为 : Multiple files w/SCP

linux + ssh 限制 + ssh 同时从多台机器到一台机器

linux - 如何使用 empty 与 telnet 交互