|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
session save to disk?Hello!
I'm using screen v. 4.00.03 (FAU) 24-Oct-06 Heres the question: Is there a way to save screen session to disk, so I could load it when PC reboots? Eg. I would like screen to try to open some directories previously opened. I couldn't find answer in google, so help appreciated. Regards _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?On Sun, Aug 23, 2009 at 03:02:44PM +0200, lukasz wrote:
> Heres the question: > Is there a way to save screen session to disk, so I could load it when > PC reboots? > Eg. I would like screen to try to open some directories previously opened. This question gets asked periodically. Currently, I don't know of any good way; there was a tool called CryoPID that had some of these capabilities but I don't think it works anymore. -- Erik _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?I wrote a very bad script that attempts to save some sort of state -
actually it writes a screenrc file that can be used to start a new screen session. It is very bad because it must be run in every shell in the screen session and names etc need to be put in by hand, but it can save directory and also load commands. I'm sure some of it could be scripted using screen -X, testing for min and max window numbers and looping through them. I'm not sure it is possible to get any other information easily either. I haven't bothered any further than since this works for me. I can email it if you think it may be of use. David Collins On 23/08/2009, Erik Osheim <erik@...> wrote: > On Sun, Aug 23, 2009 at 03:02:44PM +0200, lukasz wrote: >> Heres the question: >> Is there a way to save screen session to disk, so I could load it when >> PC reboots? >> Eg. I would like screen to try to open some directories previously opened. > > This question gets asked periodically. Currently, I don't know of any > good way; there was a tool called CryoPID that had some of these > capabilities but I don't think it works anymore. > > -- Erik > > > _______________________________________________ > screen-users mailing list > screen-users@... > http://lists.gnu.org/mailman/listinfo/screen-users > _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?On Sunday 23 August 2009 14:53:49 David Collins wrote:
> On 23/08/2009, Erik Osheim <erik@...> wrote: > > On Sun, Aug 23, 2009 at 03:02:44PM +0200, lukasz wrote: > >> Heres the question: > >> Is there a way to save screen session to disk, so I could load it when > >> PC reboots? > >> Eg. I would like screen to try to open some directories previously > >> opened. > > > > This question gets asked periodically. Currently, I don't know of any > > good way; there was a tool called CryoPID that had some of these > > capabilities but I don't think it works anymore. > > > > -- Erik > > > I wrote a very bad script that attempts to save some sort of state - > actually it writes a screenrc file that can be used to start a new > screen session. > > [...] > > David Collins > I made my own set of scripts too that write screenrc files. In my case there are a set of screenrc file for loading and another set for saving. The saving screenrc files write the scrollback buffer, the bash history and working directory. The loading ones do everything in reverse, so that these three things are restored perfectly (as far I know). The scrollback and history was somewhat tricky to restore correctly. I used the "process" command to automate things (but still leaving the user in control, things can go wrong while stuffing commands into screen/shell). The overall flow for loading/saving a session is like this: - Manually verify that every bash (or whatever) instance is at the shell prompt and ready to receive commands - Run the main "screenrc" (or "save_screenrc" file) that will: - Create each window in turn and set title if loading - Select each window in turn if saving - In both cases, type in a command which will later be executed - Manually go thru each window, and hit enter to execute the command typed in in previous step - Make sure the commands executed correctly along the way In order to set up this system to save/load a new session I use a shell script, which uses a few m4 macros to generate the screenrc scripts. The shell script reads a CSV file with the window type (bash/vim/etc), the window number, the window title and the window title using backslash escapes (used to make directories, one for each window, where files are saved). Once this info is read, it makes a directory tree for the session (1 directory per session, 1 directory per window inside the session directory), and uses a series of m4 macros to generate the screenrc scripts. Depending on window type it uses a different set of macros, which allows to somewhat adapt to different programs running under screen. Another neat feature is the ability to comment out lines (that start with #) in the CSV file to skip them on the loading/saving scripts. And to top it all up, add in a local revision control system (I use git) to keep a history of save session states, just in case something goes wrong. It turned out to be a bit more complicated that I imagined at first. But I was a bit desperate at the moment, I was about to get on a plane and cross the Atlantic soon and had a lot of screen sessions I didn't want to just close (I used stand-by a lot, just to preserve screen sessions). The sessions were also consuming the little RAM this laptop had, so I had to do something. Gerald Young _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?Hi Gerald,
In the interests of me learning how to do properly what I have done poorly, would you mind sharing your scripts? Thanks David Collins On 24/08/2009, Gerald Young <gerald.young@...> wrote: > On Sunday 23 August 2009 14:53:49 David Collins wrote: >> On 23/08/2009, Erik Osheim <erik@...> wrote: >> > On Sun, Aug 23, 2009 at 03:02:44PM +0200, lukasz wrote: >> >> Heres the question: >> >> Is there a way to save screen session to disk, so I could load it when >> >> PC reboots? >> >> Eg. I would like screen to try to open some directories previously >> >> opened. >> > >> > This question gets asked periodically. Currently, I don't know of any >> > good way; there was a tool called CryoPID that had some of these >> > capabilities but I don't think it works anymore. >> > >> > -- Erik >> > >> I wrote a very bad script that attempts to save some sort of state - >> actually it writes a screenrc file that can be used to start a new >> screen session. >> >> [...] >> >> David Collins >> > > I made my own set of scripts too that write screenrc files. > > In my case there are a set of screenrc file for loading and another set for > saving. The saving screenrc files write the scrollback buffer, the bash > history and working directory. The loading ones do everything in reverse, > so > that these three things are restored perfectly (as far I know). The > scrollback and history was somewhat tricky to restore correctly. > > I used the "process" command to automate things (but still leaving the user > in > control, things can go wrong while stuffing commands into screen/shell). > The > overall flow for loading/saving a session is like this: > - Manually verify that every bash (or whatever) instance is at the shell > prompt and ready to receive commands > - Run the main "screenrc" (or "save_screenrc" file) that will: > - Create each window in turn and set title if loading > - Select each window in turn if saving > - In both cases, type in a command which will later be executed > - Manually go thru each window, and hit enter to execute the command typed > in > in previous step > - Make sure the commands executed correctly along the way > > In order to set up this system to save/load a new session I use a shell > script, which uses a few m4 macros to generate the screenrc scripts. > > The shell script reads a CSV file with the window type (bash/vim/etc), the > window number, the window title and the window title using backslash escapes > (used to make directories, one for each window, where files are saved). > > Once this info is read, it makes a directory tree for the session (1 > directory > per session, 1 directory per window inside the session directory), and uses > a series of m4 macros to generate the screenrc scripts. > > Depending on window type it uses a different set of macros, which allows to > somewhat adapt to different programs running under screen. > > Another neat feature is the ability to comment out lines (that start with #) > in the CSV file to skip them on the loading/saving scripts. > > And to top it all up, add in a local revision control system (I use git) to > keep a history of save session states, just in case something goes wrong. > > It turned out to be a bit more complicated that I imagined at first. But I > was a bit desperate at the moment, I was about to get on a plane and cross > the Atlantic soon and had a lot of screen sessions I didn't want to just > close (I used stand-by a lot, just to preserve screen sessions). The > sessions were also consuming the little RAM this laptop had, so I had to do > something. > > Gerald Young > > > _______________________________________________ > screen-users mailing list > screen-users@... > http://lists.gnu.org/mailman/listinfo/screen-users > _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?On Tuesday 25 August 2009 08:43:04 David Collins wrote:
> On 24/08/2009, Gerald Young <gerald.young@...> wrote: > > On Sunday 23 August 2009 14:53:49 David Collins wrote: > >> On 23/08/2009, Erik Osheim <erik@...> wrote: > >> > On Sun, Aug 23, 2009 at 03:02:44PM +0200, lukasz wrote: > >> >> Heres the question: > >> >> Is there a way to save screen session to disk, so I could load it > >> >> when PC reboots? > >> >> Eg. I would like screen to try to open some directories previously > >> >> opened. > >> > > >> > This question gets asked periodically. Currently, I don't know of any > >> > good way; there was a tool called CryoPID that had some of these > >> > capabilities but I don't think it works anymore. > >> > > >> > -- Erik > >> > >> I wrote a very bad script that attempts to save some sort of state - > >> actually it writes a screenrc file that can be used to start a new > >> screen session. > >> > >> [...] > >> > >> David Collins > > > > I made my own set of scripts too that write screenrc files. > > > > [...] > > > > Gerald Young > > > > Hi Gerald, > > In the interests of me learning how to do properly what I have done > poorly, would you mind sharing your scripts? > > Thanks > > David Collins > I also included a small demo session (named SESSION_demo). I just made the session the normal way (screen -mS, to force making a new session). Then I made a couple of extra windows, changed directory and a few commands. To save that session, I copied the window list from screen, and edited it to the proper CSV format (auto-generate/SESSION_demo.csv in the archive), that is lines consisting of: type, number, name, name_with_backslash_escapes Empty trailing lines are problematic, avoid them in the CSV file. For window types I set the first one to 'main' (it's just a normal bash window, but the screenrc and save_screenrc scripts for that window also run some commands on all the other windows), and the type of the other two windows to 'bash'. Also indented the columns for easy reading (any space behind a comma is ignored). The window names are used to set the window title on screen and to make directories for each window to hold the saved files of the session (therefore the need for backlash escape version of the window name). I couldn't get the '/' or '~' characters to work correctly, so I avoid them from window names. Spaces, parentheses, backslashes are good though (need to be escaped manually though). Then I ran the script generation shell script: ./generate.sh /path-to-session SESSION_demo SESSION_demo.csv The parameters are the target path to store the session, the session name and the CSV file describing the windows it has. In this case the session will be stored at (ie. there will be one directory per window here): /path-to-session/SESSION_demo/ In order to save the session I execute: :source /path-to-session/SESSION_demo/main/save_screenrc Then cycle thru the windows, executing the script to save each window in turn (the main window's commands are executed immediately). In order to load that session I first create the screen session, and set the window that is created by default to number 39 (so it doesn't mess up the window numbers while loading), then I execute: :source /path-to-session/SESSION_demo/main/screenrc This creates the windows, therefore launching the programs. Similarly to saving, I cycle thru the window, executing the pre-typed commands. You can try out the demo session. If the archive is extracted into the '/path-to-session/' directory, then it should be possible to just do ':source /path-to-session/SESSION_demo/main/screenrc' in a fresh new screen session to load the included SESSION_demo. Otherwise, you'll need to re-run the './generate.sh' script and give it the new path where the 'SESSION_demo' directory is located. Hope this helps. Gerald Young _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
|
|
|
Re: session save to disk?Hi Gereld, thanks for sending me your scripts. I haven't had time to
go through it yet but it looks very complete. My script is considerably less functional. As it stands it needs to be executed in each shell open in the screen session. The script will basically dump the pwd, a supplied title, and supplied command into a screenrc file -f will remove a previous file -t will set the title -l is used on the last shell to tell the file to source the main screenrc -- `command` is used to execute a command on startup I didn't really think about my options too much when I wrote this and most of the hard work could be done by just parsing the window list and some screen -X magic do it all a lot easier. Here it is anyway -----------------------------------8<--------------------------------------------- #!/bin/bash ## if screen needs to be reopened and x window has been ## disconnected use this: ## in the first window run screen_open -f and run ## screen_open in the rest. In the last run ## screen_open -l. ## this will create a file $screen_open_file that contain ## the current pwds. when screen is run it will source ## this file and open all the window in the wanted dir ## if command is supplied with -c that will be run also ## ## screen_open [-f] [-l] [-t title] [-- command] ## last=0 command="" name=`basename $SHELL` nameset=0 screen_open_file='/tmp/screen_open' for f in $*; do if [[ $f = -f ]]; then echo "First window" [ -f $screen_open_file ] && rm $screen_open_file shift fi if [[ $f = -l ]]; then echo "Last window" last=1 shift fi if [[ $f = -t ]]; then echo "Window name" shift name=$1 shift fi done ## collect commands command=$* echo chdir `pwd` >> $screen_open_file echo screen -t $name $WINDOW >> $screen_open_file [ "$command" ] && echo stuff "'$command'^M">> $screen_open_file if [ $last -eq 1 ]; then echo chdir $HOME >> $screen_open_file echo source ~/.screenrc >> $screen_open_file fi _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?On Tuesday 01 September 2009 14:22:52 David Collins wrote:
> Hi Gereld, thanks for sending me your scripts. I haven't had time to > go through it yet but it looks very complete. > Perhaps, but my scripts got rather convoluted along the way. > My script is considerably less functional. As it stands it needs to be > executed in each shell open in the screen session. The script will > basically dump the pwd, a supplied title, and supplied command into a > screenrc file > I too have to go window by window, executing the commands. I don't like the idea of commands being executed in parallel in several screen windows without me seeing what's going on. If you want to try and save the history and scrollback, you can take a look into the bashrc and save_screenrc script inside one of the windows of SESSION_demo in the archive. That particular sequence of commands pretty much store/restore the history and scrollback to perfection. Its one of the nicer features I like about my scripts. It's like I never closed the bash window at all. =) > > I didn't really think about my options too much when I wrote this and > most of the hard work could be done by just parsing the window list > and some screen -X magic do it all a lot easier. > I too though of parsing the window list. But since window titles can contain spaces, it makes it kinda hard to parse it correctly. Perhaps with some regex magic. The real issue is capturing the window list. There was a question about this before: http://www.nabble.com/scripting-screen-windowlist--td23169670.html Gerald Young _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
|
|
Re: session save to disk?Gerald Young <gerald.young@...> 2009-09-01 16:16:
> On Tuesday 01 September 2009 14:22:52 David Collins wrote: > > Hi Gereld, thanks for sending me your scripts. I haven't had time to > > go through it yet but it looks very complete. > > > Perhaps, but my scripts got rather convoluted along the way. > > > My script is considerably less functional. As it stands it needs to be > > executed in each shell open in the screen session. The script will > > basically dump the pwd, a supplied title, and supplied command into a > > screenrc file > > > I too have to go window by window, executing the commands. I don't like the > idea of commands being executed in parallel in several screen windows without > me seeing what's going on. > > If you want to try and save the history and scrollback, you can take a look > into the bashrc and save_screenrc script inside one of the windows of > SESSION_demo in the archive. > > That particular sequence of commands pretty much store/restore the history and > scrollback to perfection. Its one of the nicer features I like about my > scripts. It's like I never closed the bash window at all. =) > > > > > I didn't really think about my options too much when I wrote this and > > most of the hard work could be done by just parsing the window list > > and some screen -X magic do it all a lot easier. > > > I too though of parsing the window list. But since window titles can contain > spaces, it makes it kinda hard to parse it correctly. Perhaps with some > regex magic. > > The real issue is capturing the window list. There was a question about this > before: > http://www.nabble.com/scripting-screen-windowlist--td23169670.html Yes, and it wasn't the first time [1]. In fact I had started working on a patch to the 4.0.3 code in order to allow an option to dump the windowlist to a file but got distracted by something else. I'll post it if I ever finish that. It really shouldn't be difficult. [1] http://osdir.com/ml/gnu.screen.devel/2008-03/msg00000.html However, this is what I'd really like to get working: http://savannah.gnu.org/bugs/?24937 I think it'd be easier to implement using something like the / key to begin search mode which allows entering a regex for the window title and/or number. Then let the n and N keys search forward and backward in the list like less, vim, etc. Another request I've heard is to allow selecting of double digit windows. For instance, you can't currently select window 11 using either the number keys in the windowlist mode or C-a ##, since it only listens to the first number. (Where I work we patch our screen to increase MAXWIN. Debian defaults to 40 which is just not enough in some cases.) Brian _______________________________________________ screen-users mailing list screen-users@... http://lists.gnu.org/mailman/listinfo/screen-users |
| Free embeddable forum powered by Nabble | Forum Help |