37

The use of echo-e "\ 029" does not work either. But if use strg + alt gr + ] directly in a terminal session -> it works.

I have to ask my question more concretely:
I connect an RF generator (AGILENT) via Telnet/SCPI.
If I do this manual on terminal and press at the end of the session CTRL + ALT GR +] for '^]' then close the scpi session properly and I can type quit to close the telnet session properly.
There is no error message on the display of the RF generator. So it should be.

If I do this via script the SCPI session seems not to recognize the break signal condition '^]' and will be forced to close after the end of the script (telnet and scpi). -> Message: "Disconnected by foreign host". Unfortunately, I get error messages on the display of the RF generator -> "invalid header", etc.

After successful connection appears: Connected to 192,168.10.66 Escape Character is ‘^]’ -> This is the point at issue. Manual entry in the terminal works correctly, script does not work.

My script looks something like this:

function  getIDNMessage()  
{
    (      
        echo open $1 $2  
        sleep 1  
        echo "*IDN?"  
        sleep 1  
        echo –e "\029"         # or echo “^]” does not work well  
        sleep 1  
        echo "quit\r"  
        sleep 1  
    ) | telnet > scpi_telnet.log 2>&1
}

getIDNMessage 192.168.10.66 7777    
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Bernie
  • 371
  • 1
  • 3
  • 4
  • 1
    It appears scpi has a close command (*prefix_close*), but it would not surprise me if just closing the connection would have the same effect (just falling off the end of the script will do). On startup, telnet probably checks if stdin is a tty (needed for IAC DO/DONT echo, for instance) Normal telnets disable "active" IAC session build-up when used on a non-standard port. – wildplasser Jul 28 '12 at 11:54
  • check [here](http://stackoverflow.com/questions/24337292/can-we-exit-without-error-from-telnet-with-mozrepl?lq=1) have you tried `\035` ? – Aquarius Power Jun 22 '14 at 02:34
  • 1
    CTRL + ALT GR + ] worked for me – ffghfgh Aug 08 '17 at 09:27

10 Answers10

141

On Linux it's actually:

CTRL + ] then ENTER

Finally type in the quit command.

^]

telnet> quit
Connection closed.
[fred@localhost ~]$
fduff
  • 3,671
  • 2
  • 30
  • 39
Kajackdfw
  • 1,511
  • 1
  • 9
  • 4
35

To quit telnet on redhat:
type "CTRL+5" and then type "quit"

garg10may
  • 5,794
  • 11
  • 50
  • 91
Kindi BALDE
  • 351
  • 3
  • 3
8

To Close Session Use below command

  1. Ctrl + ]
  2. telnet> quit

it works perfect in REHL and CentOS.

Pratiyush Kumar Singh
  • 1,977
  • 3
  • 19
  • 39
6

The ^] means ctrl + right bracket. As strange as that is, it works. You'll be taken to the telnet prompt, where you can type quit.

On international keyboards the ] character is often not a single key, and needs to be replaced with some other key. The correct key is typically the key to the right of P or the next key after that.

Here's a list based on comments below:

Finnish, Swedish, Norwegian, Danish: ctrl + å
French: ctrl + 6
German: ctrl + ü
Swiss: ctrl + ¨
Hungarian: ctrl + 5
Portuguese: ctrl + ´
Dutch, Belgian: ctrl + $
Canadian French: ctrl + ç
Walk
  • 1,531
  • 17
  • 21
  • These combinations may only apply to macOS. The original answer has been expanded after it was copy-pasted here: https://superuser.com/a/427 – joki Mar 20 '20 at 06:46
  • I Hope this answer have helped you. – Walk Mar 23 '20 at 04:37
  • I'm using a German keyboard and `Ctrl` + `Alt Gr` + `9` (where `Alt Gr` + `9` is `]`) did work for me. – seyfahni Apr 02 '21 at 11:19
1

It must be so. Because ^] printed in the terminal on the server means for the client side nothing. The client must catch this symbol before it will be transmitted to server and of course you can't just write it to terminal in te program running on the server.

So you need to interrupt session in other way. There are many methods.

  1. If you are inside the running program, you can simple terminate it (exit in shell or sys.exit() in python or exit() in many other languages).
  2. If you can't control program flow you can close terminal by killing the process that is owner of the terminal. You need to find the process and then use kill ... (PID of the process instead of ...).
  3. If you want to close the client from client side, you need to do the same (kill ...) but on the client side.
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
1

On my danish keyboard it was not Ctrl + å - but instead the key to the right side of å (which has a hat, a tilde and a umlaut)

tuomastik
  • 4,559
  • 5
  • 36
  • 48
Kristian
  • 11
  • 1
1

On MacOS with Turkish keyboard try:
Ctrl + Option + ü

Then,
> quit

0x01h
  • 843
  • 7
  • 13
0

Ctrl + ] This will show as ^] and then

telnet> q q is for quit

Sadee
  • 3,010
  • 35
  • 36
0

When opening a connection you can specify the escape character. e.g.

[root@localhost ~]# telnet -e % localhost
Telnet escape character is '%'.
Trying 127.0.0.1...
Connected to localhost.
Escape character is '%'.

>%

telnet> quit
Connection closed.
[root@localhost ~]#

In here, I just used the % symbol to close the session, for that I had to tell telnet to use it as an escape character. I find this useful since the character ^] could be different on different keyboard layouts.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Luc
  • 111
  • 1
  • 3
0

IF you are here in 2022 and using Mac OS or AWS Linux and using Apple Magic keyboard

^] 
telnet> quit
Connection closed.

Where ^] is "Control + ]"

Amit Meena
  • 2,884
  • 2
  • 21
  • 33