[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: session save to disk?
Re: session save to disk?
Sun, 23 Aug 2009 21:20:30 -0500
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.
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