Can't close a scpi(telnet) session with echo "^]" when I use it in a script
Asked Answered
G

10

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    
Gonad answered 27/7, 2012 at 4:57 Comment(3)
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.Chine
check here have you tried \035 ?Acro
CTRL + ALT GR + ] worked for meCommunal
B
142

On Linux it's actually:

CTRL + ] then ENTER

Finally type in the quit command.

^]

telnet> quit
Connection closed.
[fred@localhost ~]$
Bleary answered 20/11, 2014 at 17:15 Comment(4)
And then type quit. This is even difficult than exiting vi.Limerick
Instead of typing quit you can also press CTRL + D (meaning "end of stream") to exit telnet.Taryn
Instead of quit, you can type q.Bertilla
This is difficult on MacBook. Recommendations?Dorking
S
36

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

Soosoochow answered 19/5, 2017 at 15:30 Comment(3)
Worked in arch linux as well.Joaquin
Thank god.. on my Danish keyboard if I pressed CTRL- alt-gr 9 (altgr 9 is ] on dk keyboard) my mac would just change windows..Deliver
I am using SLES 11 and this is the only proposed solution that works for me.Lattimore
S
8

To Close Session Use below command

  1. Ctrl + ]
  2. telnet> quit

it works perfect in REHL and CentOS.

Stull answered 7/11, 2017 at 10:11 Comment(0)
C
7

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 + ç
Combatant answered 13/9, 2017 at 9:35 Comment(3)
These combinations may only apply to macOS. The original answer has been expanded after it was copy-pasted here: superuser.com/a/427Quadruplex
I Hope this answer have helped you.Combatant
I'm using a German keyboard and Ctrl + Alt Gr + 9 (where Alt Gr + 9 is ]) did work for me.Verde
P
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.
Pm answered 27/7, 2012 at 5:27 Comment(0)
T
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)

Trews answered 6/10, 2017 at 8:16 Comment(1)
In my Norwegian keyboard shift + alt + 9 worked (since alt + 9 is "]" )Dishevel
S
1

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

Then,
> quit

Stop answered 25/7, 2019 at 13:46 Comment(0)
P
0

Ctrl + ] This will show as ^] and then

telnet> q q is for quit

Presuppose answered 25/5, 2018 at 8:29 Comment(1)
Depends on the keyboard setting.Mankind
U
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.

Untruth answered 24/8, 2021 at 2:22 Comment(0)
S
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 + ]"

Stereobate answered 18/11, 2022 at 6:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.