[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: session save to disk?

From: Gerald Young
Subject: Re: session save to disk?
Date: Tue, 25 Aug 2009 11:18:57 -0500
User-agent: KMail/1.9.9

On Tuesday 25 August 2009 08:43:04 David Collins wrote:
> On 24/08/2009, Gerald Young <address@hidden> wrote:
> > On Sunday 23 August 2009 14:53:49 David Collins wrote:
> >> On 23/08/2009, Erik Osheim <address@hidden> 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

Yes, no problem.  I have attached an archive with the scripts.

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:
./ /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):

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 './' script and give it the 
new path where the 'SESSION_demo' directory is located.

Hope this helps.

Gerald Young

Attachment: auto-generate.tar.gz
Description: application/tgz

reply via email to

[Prev in Thread] Current Thread [Next in Thread]