let telnet execute single command in one line

允我心安 提交于 2019-12-03 11:42:17

I found expect to do exactly what i want, wait for a certain output and then act upon it:

expect << EOF
spawn telnet localhost 4242
expect -re ".*>"
send "show network\r"
expect -re ".*>"
send "exit\r"
EOF

If you don't have to log in or anything, you can use a "here document" like this:

telnet localhost 4242 << EOF
show network
EOF
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!