screen-users
[Top][All Lists]
Advanced

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

Shell script to manage screens


From: Gokulmuthu Narayanaswamy
Subject: Shell script to manage screens
Date: Fri, 12 May 2006 14:21:36 +0100 (BST)

Hi,

    I use a shell script to manage my various screen sessions.
It uses dialog to display the screens on the current machine
and lets me choose the screen to attach to. I thought it will
be useful to others too.

    You need to put this somewhere on your machine and add a
line to the end of your ~/.bash_profile to execute this. For
example, this is what I have on the last line of my .bash_profile
. $HOME/bin/choosescreen.sh

With regards,
Gomu.

#!/bin/sh
#
# Screen chooser
#
# To activate this, put this file in your home directory and add
# . , $HOME/choosescreen.sh
# at the end of the .bash_profile in your home directory.
#
# If you have any questions, ask address@hidden

#==========  Configurable parameters  ====================
# Seconds to wait before defaulting to no screens mode
timeout=5
# Instructions to detach and quit are displayed at the title bar in novice mode
novice=1
#==========  End of Configurable parameters  ====================

# Create screen dir in /tmp away from NFS
screendir=/tmp/screen.$LOGNAME
mkdir -p $screendir
chmod 700 $screendir
export SCREENDIR=$screendir

# Compute the number of screens and height of the dialog
numscreens=`screen -ls | /bin/grep "(" | wc -l`
numscreens=`expr $numscreens + 1`
height=`expr $numscreens + 7`

# Generate the list of screens argument for radiolist dialog
screenlist=`screen -ls | /bin/grep "(" | sed -e "s/ ???/?/" | (
while read thisscreen
do
    screenlist="$screenlist $thisscreen off"
done
echo $screenlist
)`

# Get the screen to switch to from user
chosenscreen=`dialog --timeout $timeout --stdout --radiolist "Choose screen to
attach to" $height 40 $numscreens New screen on $screenlist`
#echo dialog --stdout --radiolist \"Choose screen to attach to\" $height 40
$numscreens New screen on $screenlist
if [ "$chosenscreen" = "New" ]
then
    clear
    # Get the name of new screen
    screenname=`dialog --timeout $timeout --stdout --inputbox "Name: " 8 20`
    screenname=`echo $screenname | sed -e "s/[ \t]/./g"`
    if [ "$screenname" = "" ]
    then
        screen
        exit
    else
        if [ "$novice" = "1" ]
        then
            screen -S "$screenname" -t "$screenname : Cntrl-A d to detach :
Cntrl-d to quit"
        else
            screen -S "$screenname" -t "$screenname"
        fi
        exit
    fi
elif [ "$chosenscreen" = "" ]
then
    clear
    echo
    echo Warning: Not running in screen mode. You will lose your work if
network connection is lost.
    echo
else
    screen -q -r -D $chosenscreen
    if [ "$?" != "0" ]
    then
        clear
        echo Could not attach to the screen. May be the system was restarted.
To clean up this screen run
        echo "     export SCREENDIR=$screendir"
        echo "     screen -wipe $chosenscreen"
        echo
        echo Warning: Not running in screen mode. You will lose your work if
network connection is lost.
        echo
    else
        exit
    fi
fi


------------------------------------------------
Webpage: http://www.geocities.com/gokulmuthu/
------------------------------------------------

Send instant messages to your online friends http://in.messenger.yahoo.com 




reply via email to

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