Wednesday, June 15, 2011

screen + minicom (how to get out of)

So, I did it again. You see, I like to use minicom as a terminal program since it plays nice with my usb-to-serial cables and my serial devices (Sun and AIX workstations, Seagate Dockstar, Pogoplug, routers, switches). And I have used it long enough to remember some of the commands. I also like screen, which allows me to run multiple sessions on different machines and stop and resume them as needed; kinda like running vnc/rdp but in command-line.

The problem begins when I try to use them together. I really should not do that because you can connect to a serial port from screen by doing something like

:screen /dev/ttyUSB0 115200
(some devices I use have their default port speed set to 9600, others like the one in this example to 115200)

But, force of habit (read: lazyness) or distraction (did you see that ant crawling up the wall?) caused me to start minicom right in screen. At first that does not seem to be a bad idea; after all, it would be nice to connect to the console of, say, a Brocade fabric switch, start something there, log out, and then come back to it later. But, problem is that screen and minicom by default use the same CTRL-A sequence to enter commands. So, if I want to send a CTRL-A X (exit) to minicom, screen will think I am talking to it and then lock the screen. Not fun.

Some of you will argue that I could remap the escape sequences for each program so they will not match, but hindsight is 20/20: it does not do me any good once they are already running inside each other. Another option would be to close that screen session, which would quit minicom... but not gracefully. As a result, that serial port (/dev/ttyUSB0 in my case. Yes, it is USB but you know exactly what I am talking about) would not be freed even if I remove the serial-to-USB cable. We need something better.

If we look at the screen man page, we will find the escape sequence CTRL-a a. What it does is send a CTRL-a escape to the screen session, so whatever program running in that session can grab and run away with it. So, what we want to do is probably CTRL-a a x, which should quit minicom. Now, the trick here is speed: you have to press CTRL-a together, then immediately a and then x. It took a while for me because I was either not typing fast enough or just mashing keys together. But, once I got it just right, I was rewarded with the minicom quit dialog box:

+----------------------+
|    Leave Minicom?    |
|     Yes       No     |
+----------------------+

And now I was able to properly quit minicom. Life was good once again.

Do I plan on running minicom inside screen again? Not if I can avoid it. But, if I can't, now I have a way out.

3 comments:

miTgiB said...

Let me flash my lazy card for admission to this party, thanks for the tip!

Uttaran said...

Thanks +1 to screen +1 minicom +1 to laziness

Ken L said...

Finding this helpful in 2023 :-)