Link to home
Start Free TrialLog in
Avatar of nascar_3
nascar_3

asked on

Need to echo a "^]" in script

I'm trying to write a script that telnets to a remote DIGI printer port, sends the print job and then disconnect from the remote port by sending a "^]" ( "ctrl-]" which is the telnet escape character). It works perfectly as far as establishing the telnet connection and sending the print job to the printer, but I cannot figure out how to send a "^]" by using the ECHO command. Any one know how this could be done, or is there a better command I could use in the script to break the telnet connection?
Avatar of grantk
grantk

The quick answer is while using vi to edit the script, instead of typing "^]", type the following keystrokes:
ctrl+v esc ]

Explaination:
In vi, as the escape character is used to switch from edit mode to command mode, you need to use ctrl+v which "quotes" special characters in edit mode.

Further Thoughts
Using telnet is not a great solution. Consider having a look at something like netcat.


Avatar of nascar_3

ASKER

grantk,

 Thanks for the quick answer, but that didn't really work as such. I mean, I'm familiar with the <Ctrl-V> in vi, in fact I've used it in this same script for a CR by doing <Ctrl-V> then <ENTER>. It shows up in the script as ^M and issues a carriage return, no problem. BUT when I tried <Ctrl-V> then <Ctrl-]> the result isn't the same. I DID TRY the <Ctrl-V> then <ESC-]> like you suggested, but it shows up as ^[] in the script and just prints a "]" when it runs.

 I know Telnet isn't ideal for this, but this is a short term application and doesn't warrant exploring new avenues like netcat (not sure what that is even). I'm stuck with what I have. My only problem is that I cannot get the telnet session to break after its connected.

It will break just fine when I try it from a CRT by actually hitting <Ctrl-]>+<ENTER>. But I need it to break automatically by echoing that sequence directly after a print job finishes.

Again, maybe the keystrokes needed after the <Ctrl-V> are just somewhat different than what I've tried, or there is a better command than "echo" to do the job ?
Avatar of ozo
When you tried <Ctrl-V> then <Ctrl-]> what was the result?
Oops, re-reading my answer makes me realise I may have been a little tired when I wrote it ;-).
Try this:
ctrl+v ctrl+]

It should come out as "^]" in vi and appear as 1 character. If this doesn't work, you may need to have a look at something like expect to solve the problem.
Another trick you can use is wrap the program in a shell-script. Assume the program you're running is called "foo". A shell-script called "bar" can be created that runs foo, waits for a few seconds and then issues a kill to foo. Again, messy.


grantk,

 Thanks, but If you re-read my first rejection, I had already tried the <ctrl+v> <ctrl+]> and did not get the desired result.

to answer OZO's question, this does just what grantk said, it shows as a ^] in the script as 1 character, but is NOT breaking the telnet connection. The line reads:
echo "^]^M" |lp (output to serial port hooked to DIGI)

again, if I hook up a CRT and hit the actual keys <Ctrl+]> and then <ENTER> the connection breaks just fine...

Just to clarify what I'm trying to do....

DG UNIX system (NO network TCP/IP on this system)
DG serial printer output to DIGIPORT-A[port#3]
DG sends echo command to TELNET DIGI PORTSERVERS together
PORTSERVER-A[port#3] TELNETS to PORTSERVER-B[port#8]
printjob is sent to printer hooked to PORTSERVER-B[port#8]
printjob prints great! (everything great to this point)
This is where I need to "^]" TELNET to get a command line
echo command "close" TELNET session and free up ports
Next print job would start TELNET over again...........

I need to cancel the TELNET to allow print jobs from a different AIX system to also go to that same printer on PORTSERVER-B[port#8] coming from the IP network. Those print jobs won't go to printer as long as TELNET session from DG is active. Once TELNET closes and ports are free, the AIX print jobs are allowed to continue on to printer.  
 
ASKER CERTIFIED SOLUTION
Avatar of artemb
artemb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
 
Thanks,
Moondancer
Moderator @ Experts Exchange