Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

let telnet execute single command in one line

Tags:

shell

telnet

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

like image 467
Nick Russler Avatar asked Apr 05 '11 11:04

Nick Russler


2 Answers

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
like image 80
Nick Russler Avatar answered Sep 21 '22 07:09

Nick Russler


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
like image 22
Ernest Friedman-Hill Avatar answered Sep 19 '22 07:09

Ernest Friedman-Hill