#!/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的时候。我刚刚意识到当我完全掌握了我的路由器配置时。
答案 0 :(得分:1)
问题已解决
#!/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的时候。我刚刚意识到当我完全掌握了我的路由器配置时。
答案 1 :(得分:0)