在shell脚本中使用expect实现telnet登陆路由器

发布时间:2024-10-12 点击:54
expect是基于tcl的,作为一个脚本语言,expect能在无需管理员参与的情况下实现自动交互(比如passwd,fsck,telnet等)。expect也能用于自动测试一些应用程序。
这里博主以登陆路由器为例,先简单了解expect实现telnet自动登陆路由器的过程。当然也可以使用expect脚本ssh登陆服务器进行自动化管理。
#!/usr/bin/expectspawn telnet 192.168.1.1expect "*username:*"send "yourname\\r"expect "*password:*"send "yourpwd\\r"send "en\\r"expect "*password:*\\r"send "yourpwd\\r"send "sys show\\r"send "exit\\r"expect eof运行测试一切正常。
spawn telnet 192.168.1.1
trying 192.168.1.1…
connected to 192.168.1.1.
escape character is ‘^]’.
username:yourname
password:
tp-link > en
enter password:
tp-link # sys show
cpu used rate: 17%
tp-link > exit
connection closed by foreign host.


云服务器怎么调试摄像头
直播推流是什么?怎么进行直播推流?
什么是域名系统
账号资料修改-市场咨询
阿里云服务器配置规则在哪
网站云服务器一年多少钱
好用的社交软件有哪些 免费的社交软件推荐
扫描二维码无法下载备案的