linux – 如何使用Expect自动化telnet会话?
发布时间:2020-12-28 04:17:26 所属栏目:Linux 来源:互联网
导读:我正在尝试编写一个expect脚本来自动执行telnet.这就是我到目前为止所拥有的. #!/usr/bin/expect# Test expect script to telnet.spawn telnet 10.62.136.252expect foobox login:send foo1rexpect Password:send foo2rsend ec
|
我正在尝试编写一个expect脚本来自动执行telnet.这就是我到目前为止所拥有的. #!/usr/bin/expect # Test expect script to telnet. spawn telnet 10.62.136.252 expect "foobox login:" send "foo1r" expect "Password:" send "foo2r" send "echo HELLO WORLDr" # end of expect script. 基本上,我想要做的是telnet到以下IP地址,然后回应HELLO WORLD.但是,似乎脚本在尝试telnet后失败了……我不确定它是否能够接受登录和密码输入,但它并没有回应HELLO WORLD.相反,我只是得到这个输出: cheungj@sfgpws30:~/justin> ./hpuxrama spawn telnet 10.62.136.252 Trying 10.62.136.252... Connected to 10.62.136.252. Escape character is '^]'. Welcome to openSUSE 11.1 - Kernel 2.6.27.7-9-pae (7). foobox login: foo1 Password: foo2~/justin> 解决方法您在没有首先预期提示的情况下发送echo命令.尝试:# after sending the password expect -re "> ?$" send "echo HELLO WORLDr" expect eof (编辑:吉安站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- linux – pthreads线程在堆栈中预先故障的最佳方法是什么?
- 如何在linux mint下的zsh中设置virtualenvwrapper?
- 使用标准的linux工具链查找/替换htmlentities?
- linux – 在ARM上构建mongo shell 3.2.x(armv7l / arm64 /
- linux – 如何显示Bash字符串中包含的唯一单词?
- 在同一个Linux目录中有几百个或几千个文件可以(性能方面)吗
- linux内核引用是否计算内核对象?
- linux – i386:x64-32 vs i386 vs i386:x86_64之间的区别
- linux – 我被黑了吗?未知进程dsfref,gfhddsfew,dsfref等将
- linux – iwconfig – 通过wifi在终端上连接网络
