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.  
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.  
 
0 nhận xét:
Post a Comment