Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to echo a "^]" in script

Posted on 1999-07-20
7
Medium Priority
?
331 Views
Last Modified: 2010-04-21
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?
0
Comment
Question by:nascar_3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Expert Comment

by:grantk
ID: 2011583
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.


0
 

Author Comment

by:nascar_3
ID: 2011584
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 ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 2011585
When you tried <Ctrl-V> then <Ctrl-]> what was the result?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:grantk
ID: 2011586
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.


0
 

Author Comment

by:nascar_3
ID: 2011587
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.  
 
0
 
LVL 1

Accepted Solution

by:
artemb earned 400 total points
ID: 2011588
There are several options:
1) If you use bash then "echo -e '\E'" will output <ESC> character.
2) If you cannot make echo print <ESC>, then make telnet understand some character you can print as an escape sequence. Use "telnet -e ^X" to set ^X as an escape character (or use your favorite)
3) You may just kill telnet without all this escape tricks.
Result will be the same and it's way easier and more reliable. After all, you can always use "kill -9". :-)
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6821547
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question