let telnet execute single command in one line

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

hey i can login into telnet with "telnet localhost 4242" now i want to execute a single command "show network".

How can i do this in one line ?

something like that

$ telnet localhost 4242 <- "show network"

woa here the output i want

回答1:

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 


回答2:

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 


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