Automating GNU screen startup

At work I use GNU screen with one window per server (ssh connection), and when I loose my screen, it takes minutes to rebuild the naming and the ssh connections …

So I searched and found a PHP version on Jon’s blog but I don’t like PHP and don’t want a PHP cli on my machine (even to start screen !)

So I rewrote it in bash (not sh, bash, to have brace expansion !)

Enjoy :

#!/bin/bash -f
 
SCREEN_NAME=julien
SERVERS=$(echo {julien,root}@dev root@{www,sql}{1,2} root@media{1,2,3,4,5,6}
 
 
 
 
screen -dmS "$SCREEN_NAME"
NUM=0
for SERVER in $SERVERS
do
    NUM=$((NUM + 1))
    screen -S "$SCREEN_NAME" -X screen
    if [ z"$SERVER" != z"" ]
    then
        screen -S "$SCREEN_NAME" -p $NUM -X title "$SERVER"
        screen -S "$SCREEN_NAME" -p $NUM -X stuff "ssh $SERVER $(printf \\r)"
    fi
done
printf "Done,  now you can join your screen with :\n"
printf "$ screen -dr -S $SCREEN_NAME\n"

Don’t forgot to start your ssh-agent just before starting this script !

PS : If you don’t have a ssh-agent, you may want to remove the $(printf \\r) and press enter yourself.

This entry was posted in Code. Bookmark the permalink.

2 Responses to Automating GNU screen startup

  1. Jon says:

    Yay! Non-php version!

    I love my PHP but I realize that not everyone does. I’ve updated the blog to include a link here.

Leave a Reply to Jon Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>