[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I get a windowlist to STDOUT?
From: |
Rod Nussbaumer |
Subject: |
Re: How do I get a windowlist to STDOUT? |
Date: |
Wed, 04 Jan 2006 10:10:52 -0800 |
User-agent: |
Mozilla Thunderbird 1.0.7-1.4.1 (X11/20051007) |
Aaron Griffin wrote:
On 1/3/06, Robert Blackwell <address@hidden> wrote:
I have been digging around to find a nice way to output the windowlist to
STDOUT but have not seen an easy solution.
I would like to be able to do something like this
screen -X windowlist > windows.txt
I've been looking for something similar with the paste command (if
that's the right name) - so "screen -X paste" will dump the current
copy buffer. I don't think any of the commands actually output to
stdout when run from the command line. Might be a nice thing to hack
in though.
I think this perl subroutine does what you are trying to accomplish.
Note that it does require screen to be setuid root, and obviously it
runs 'outside' of screen itself.
I use this as part of a Tk GUI that allows our users to select from a
menu of available multi-user sessions. There is a bit of Perl/Tk code in
here that reflects this. Maybe this is helpful to someone.
I hope this makes it through without being destroyed by word-wrap.
#----------------------------------------------------------
sub refreshScreenList {
#
# GNU screen stores it's list of active screen sessions in the
# /tmp/screens/S-* directory tree. We use the directory names to
# see which users *potentially* have screens alive. Only the
setuid
# screen program can see inside the directory tree, so we call
# it to do the work, once in each subdirectory.
#
opendir( SCREENS, "/tmp/screens" );
my @screensDir = readdir SCREENS;
closedir SCREENS;
#
# Blank the list, then rebuild it
#
$screenList -> delete( 0, 'end' );
#
# Scan /tmp/screens/S-* for all users' screen sessions
#
foreach my $dir ( @screensDir ){
$dir =~ s/^S-//;
# print $dir,"\n";
#
# Get screen to look into the directroy, and grab what it
says.
#
open( SCREENLIST, "screen -S ".$dir."/ -list |" );
my @screens = <SCREENLIST>;
close( SCREENLIST );
#
# Parse the output from screen, looking for a report of a
live screen
#
foreach my $screen ( @screens ){
# Matching '1234.Any screen description'
if( $screen =~ /^\s+[0-9]+\./ ){
my $scr = $screen;
if( $scr =~ m/\([^)]+\)/ ){
chomp $scr;
$scr =~ s/\([^)]+\)//g; #
remove attachment status text
my $status = $&; # save
status info
$scr =~ s/^\s//g; # trim
leading and trailing spaces
$scr =~ s/\s$//g; #
#
# Compose string to put into list
widget
#
my $listItem = $scr." ".$status."
".$dir;
$screenList -> insert( 'end', $listItem
); # Append to list widget.
}
}
}
}
}
#----------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rod Nussbaumer,
Electronics Development Group, TRIUMF
Vancouver, Canada.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~