Progress on the screen shutdown script

A few months ago I mentioned a script intended to gracefully shut down all the programs I normally run in screen, and bring the entire session to a halt. As things are now I have to step through each program and issue the native “quit” command(s), which isn’t terrible, but with only minor variations, should be easily handled through a script.

The problem of course, is that some of those programs, like mc or hnb just as examples, need control characters to quit cleanly, and through screen’s stuff command, things get a little hairy.

Boldewyn‘s post from a few days ago gets me a little closer to where I want to be. With the keypress sequences mentioned there, my script now looks like this.

#!/bin/bash
screen -p alpine -X stuff qy
screen -p centerim -X stuff ^[^[qq
screen -p elinks -X stuff Q
screen -p hnb -X stuff ^Qy
screen -p htop -X stuff q
screen -p mc -X stuff "exit ^M"
screen -p vim -X stuff :wq!
screen -p wyrd -X stuff Q

The CTRL+V keypress to “translate” the control characters to text was a big step forward. The long, backslash-preceded codes that I was using before were being sent through as straight keypresses, but this sends through a command character, which works well for things like mc or hnb.

Usually. It’s odd, but it seems like sometimes, the script works but sometimes things still get huddled up on mc’s prompt line, or hung at hnb’s save-before-closing prompt. Sometimes it seems like the script will work if it’s executed from within screen, but not if it’s cued from another tty or if screen is detached. This is definitely better and sometimes seems to get the job done, but it’s just not “there” yet — to borrow a phrase from Linux detractors. :twisted:

In any case, I will continue to pursue this, and see if I can pin down the when and the where of the why it doesn’t quite do the trick. :)

About these ads

3 thoughts on “Progress on the screen shutdown script

  1. Dieter_be

    hmm. what are you smoking?
    Don’t these programs respond to sigterm? If not, patch them to do so. It would be much cleaner then this ;-)

    Reply
  2. Gullars

    If you had taken the time to read the comments on the original post you would be wiser, I’ll suggest you do that before trying to be a smart ass…

    Reply

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