Chinaunix

标题: 关于使用here document来telnet的问题 [打印本页]

作者: df110341243    时间: 2011-11-30 16:50
标题: 关于使用here document来telnet的问题
脚本如下:
#!/bin/bash
telnet 192.168.1.1<<EOF
username
password
ifconfig
EOF
执行之后的输出为:
Trying 192.168.1.1...
Connected to 192.168.1.1 (192.168.1.1).
Escape character is '^]'.
Connection closed by foreign host.

也就是没有执行ifconfig命令,远端就直接把连接给close了,求解……
作者: bikong0411    时间: 2011-12-01 09:14
肿莫不写端口~
作者: cjaizss    时间: 2011-12-01 09:42
telnet需要终端输入,你可以用expect
作者: df110341243    时间: 2011-12-01 09:55
回复 2# bikong0411


    telnet 默认端口23吧?
作者: df110341243    时间: 2011-12-01 09:57
回复 3# cjaizss


    呃 我会用expect的方式 就是学习到here document的时候 想试试 然后……
作者: cjaizss    时间: 2011-12-01 09:57
回复  bikong0411


    telnet 默认端口23吧?
df110341243 发表于 2011-12-01 09:55



    对,默认是23。
作者: cjaizss    时间: 2011-12-01 09:58
回复  cjaizss


    呃 我会用expect的方式 就是学习到here document的时候 想试试 然后……
df110341243 发表于 2011-12-01 09:57



    如果程序需要标准输入是终端,那么here document就无法搞定
作者: df110341243    时间: 2011-12-01 11:05
回复 7# cjaizss


    啊 原来是这样 那明白了 非常感谢




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2