1

I am sending a command to remote server via SSH as

ssh raja@remote_host "telnet 192.168.56.101 8080"

But we all know that , to quit from telnet we need to get back to telnet prompt with CTRL+^] and then enter with quit.

But how I can do that with out using any other tools/programs like xdotool?

  • 1
    Not sure what are you trying to achieve, since your question is really chaotic. Can you try once more? Ideally with format what you do, what happens and what you expect/want to happen. – Jakuje Dec 30 '15 at 14:08
  • Try giving ssh a -t option; then you may be able to type ^]. – Mark Plotnick Dec 30 '15 at 15:19
  • Even without -t doing ctrl+] (or other -e value) quit ret does work, it just doesn't prompt as it does on tty. – dave_thompson_085 Aug 18 '17 at 12:54
2

Did you try something like this from another ssh session:

ssh raja@remote_host "ps -ef | grep telnet | grep 8080 | grep -v grep | awk '{print $2}' | xargs kill"

The reason for the cascaded grep commands is to prevent an accidental killing of some other telnet session, unrelated to what you actually want to kill.

  • Is there any way I can kill it from same SSH session ? – rɑːdʒɑ Dec 30 '15 at 17:34
  • instead of running a single command from your local machine, you can put this command in a script, and include the command I gave above preceding this command in the same script, and schedule it to be run 2-3 minutes after it is run using at command. It will give you enough time to do your telnet test and it will kill the process in the time you specified. If you are asking about sending an interactive kill process by sending a ^] escape sequence, I don't know the answer to that as it may require quite a bit of termcap study, to figure out necessary sequence of characters. Not my forte! – MelBurslan Dec 30 '15 at 21:51
0

Instead of telnet, you can use Bash shell to achieve the same, e.g.

ssh user@remote_host bash -c 'printf "some_command\r\n" > /dev/tcp/192.168.56.101/8080'

Other examples: Grep regex Stdout to telnet, get all keys set in memcached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.