Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send commands to telnet and leave session open [closed]

Tags:

unix

pipe

telnet

I have to connect to a remote server via telnet and want to send file input there.

This is a processor emulator (MCF68k), so I can't just scp the file to the server and run from there.

I can send input like this:

telnet host.name < input.file

Which will successfully transmit the data to the server and run the commands stored that I want. However, I need the telnet session to stay interactive (not terminate).

How do I pipe a file to a command, then return control of stdin to the terminal and keep the interactive session open?

Very Late Edit:

I think this can be done using expect:

man expect: http://www.manpagez.com/man/1/expect/

python wrapper: http://www.noah.org/wiki/pexpect

like image 390
Jamie Wong Avatar asked Sep 30 '10 01:09

Jamie Wong


People also ask

Which telnet command is used to leave a telnet session?

To exit the Telnet session, type Ctrl + ] on your keyboard. This changes the command prompt to show as telnet>. Back in the terminal, type in the word 'close' to close the session.

How do I keep telnet session alive?

Wrap the telnet within an expect script that detects lack of input. It sends the escape sequence control-] to the telnet client to get the command prompt telnet> , and issues the command send nop (no-operation). I assume this is enough to keep the connection alive.

What is escape character in telnet?

The default escape sequence is Ctrl-] for the telnet command, Ctrl-T for the tn command, or Ctrl-C for the tn3270 command.


1 Answers

Does cat input.file - | telnet host.name work?

like image 71
Jack Kelly Avatar answered Oct 13 '22 09:10

Jack Kelly