Puzzled by screen’s stuff

One little problem I’ve been trying to decipher for my own benefit is a script to shut down screen. I usually have five or six applications running in screen, and when I close the machine for shutdown, I manually step through each program, giving it the command to close (and sometimes save).

Since it’s possible to pipe keystrokes through screen to the appropriate application, it seems to follow that a simple five- or six-line series of commands could cleanly save and close everything I usually have running. Technically, the command looks like this:

screen -p elinks -X stuff Q

A shifted Q is a quick shutdown command for elinks, and sending that through screen to the window entitled “elinks” (which is always called “elinks,” because it’s triggered at startup in my .screenrc) causes the application to stop. This will shut down alpine, since the command there is a q, followed by a y to answer yes to the confirmation.

screen -p alpine -X stuff qy

And so forth and so on. htop can close with a q, wyrd with a shifted Q. The problem comes with applications that require function keys as shutdown commands, such as mc‘s F10 close command, or a series of Escape keys for centerim, or hnb which wants a CTRL+Q to quit.

For some reason, using the keystroke sequences in the GNU/Screen user’s manual don’t enter as escaped, instead they spill onto the screen as typed characters, or are ignored since they don’t form an escape sequence. So if I try this, which I think sends an F10 command to Midnight Commander:

screen -p mc -X stuff \033[21~

The console command line in mc shows 033[21~ after the command prompt, as if I had typed those letters directly myself. Chances are I’m feeding it the wrong commands, or there is some other special switch that I need to add to get it to actually send through as a keystroke instead of raw text.

I could probably just use screen’s default kill switch (CTRL+A CTRL+\) to close everything, but I don’t know if I am comfortable with that. Given that these commands are available and work for some cases, I probably just need a nudge to get the whole thing working as imagined. :|

About these ads

9 Responses to “Puzzled by screen’s stuff”


  1. 1 William 2010/04/13 at 10:37 AM

    So a little research into your programs and see which ones can be shut down safely via SIGTERM. The ones that can, you would use the kill command to send SIGTERM to all of those processes.

    • 2 K.Mandla 2010/04/13 at 1:41 PM

      I probably could. The added bonus in getting this to work (as I imagine it) would be that I could tie the script to a preprogrammed keystroke. That would give me a one-key command to automatically save open notepads, close all the applications neatly, exit screen and be ready for a shutdown.

      Or that’s how it would work in my little world. … :roll:

      • 3 vespas 2010/04/14 at 12:11 AM

        if apps shutdown safely with SIGTERM then you could just shut down the machine, as init sends a SIGTERM to everything! I’m guessing that other than unsaved buffers in vi (or similar), it doesn’t really matter if you just kill everything.

  2. 4 foo 2010/04/13 at 3:51 PM

    I prefer using the termcap name instead of the command sequence.
    screen -p mc -X stuff -k “k;”
    should do the trick for you.

    You may also want to have a look at tmux, it’s easier to configure and under active development.

  3. 5 saintsteele 2010/04/14 at 12:37 AM

    To shut down rtorrent (which I think requires ctrl-q), I use “screen -X -S tor eval ‘stuff 21′” (without the double quotes, fixing wordpress’s “smart” quotes, and “tor” is always the name of my rtorrent session). Probably “-p” is a better choice than “-S”, although it’s been working fine for me.

    • 6 saintsteele 2010/04/14 at 1:46 PM

      Wow, I just realized that wordpress awesomely stripped out part of the command I just posted: instead of “21″, that should have said the equivalent of backslash-zero-two-one.

      • 7 boldewyn 2010/06/23 at 6:52 PM

        It seems, that eval and the -p switch don’t play well together. At least on my machine, the string is always stuffed in the current window.

  4. 8 Boldewyn 2010/06/23 at 6:37 PM

    I found this post through Google, because I had the same problem. However, using xterm and bash under Win/Cygwin I solved it by typing the control characters via the Ctrl-V escaping:

    screen -X -p mc stuff [Ctrl-V][F10][Ctrl-V][Enter]

    which just did as requested.


  1. 1 Progress on the screen shutdown script « Motho ke motho ka botho Trackback on 2010/07/07 at 8:53 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,958,984 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: