Shell脚本成功登录telnet,之后如何发出命令? [英] Shell script successful telnet login, how to issue commands after that?
问题描述
#!/usr/bin/expect -f
spawn telnet 10.21.0.17
expect -re "login"
send "admin\n"
expect -re "Password"
send "supersecurepassword\n"
interact
按预期工作.运行脚本后,我登录到在行spawn telnet 10.21.0.17
works as expected. Upon running the script I am logged in to whatever telent IP I used in the line spawn telnet 10.21.0.17
然后它将我带到AP的外壳
Then it drops me to the Shell of the AP
WAP->
WAP->
如何发出其他命令?我想先发布reboot
,然后再发布sleep 20
,最后是exit
.
How do I issue further commands? I'd like to issue reboot
and then maybe a sleep 20
and finally exit
.
我尝试使用echo
和expect
失败.我还尝试了删除interact
的操作,但没有成功.有什么想法吗?
I have tried using echo
and expect
with no success. I've also tried with removing the interact
with no success. Any ideas?
推荐答案
This was resolved by simply adding a sleep
before the expect
, and of course not including interact
, the following works well:
#!/usr/bin/expect -f
spawn telnet 10.21.0.17
expect -re "login"
send "admin\n"
expect -re "Password"
send "supersecurepassword\n"
sleep 5
expect "WAP"
send "reboot\n"
send "exit\n"
作为参考,这用于在D-Link DAP-2590无线接入点上自动重启.现在,我已经知道了这一点,我可以将其用于其他用途:更改密码等.希望将来对其他人有所帮助.
For reference, this was used to automate a reboot on a D-Link DAP-2590 wireless access point. Now that I know this though, I may use it for other things: changing passwords, etc. Hope it helps someone else in the future.
这篇关于Shell脚本成功登录telnet,之后如何发出命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!