screen-users
[Top][All Lists]
Advanced

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

Screen Start Script


From: Danny
Subject: Screen Start Script
Date: Sun, 9 Jul 2006 13:10:34 -0700 (PDT)


I have yet to find an example online that actually shows how to start screen windows in a straight forward way. Actually, I have not been able to find any sort of straight forward way. But I thought I would post my solution to my
problem and ask for advice on better ways to do this.

I basically use screen to be logged into several systems at once for differn't parts of my company's network. On occasion something makes screen freeze (im thinking its irssi) so I end up killing all the sessions and doing them all over again. This happened a few too many times in one day, so I decided to make a script out of it.

My first attempts were just to launch a normal screen just like I would typing on the command line;

screen bash
screen ssh sever1
screen ssh server2 ... etc

But of course you would have to pass arguments to the newly created bash shell you started screen with, and that left me in an odd state of trying to do things like;

screen bash & screen ssh server1 & screen ssh server2, etc...

That wasn't going to work either (yeah, im still a bit green on this stuff)
because it was backgrounding the other processes ( i think?)

Then I thought, ummmm... maybe a case statement would work?

Gave this a shot;

case "$1B" in
   start   ) screen bash & setscreen.sh phase2 ;;
   phase2  ) screen -t SV1 3 "ssh server1"
             screen -t SV2 4 "ssh server2"
             screen -t IRC 1 "irssi"  ;;
esac

Somehow this kind of worked, but not quite right. Screen would do some weird word wrapping, and the terminal was basically unusable.


What has actually worked is this, and I think it sucks, but it does work how I want it too:

I made one script, with two config files that bash can call from --init-file, basically reparsing commands after I got into a new shell. Only I really hate having more than one file for a simple purpose, I had to create three:

Script: screen-start.sh

#See if ssh-agent is running:
if [ -z "$SSH_AGENT_PID" ]
  then
eval `ssh-agent bash --init-file ~/bin/add-key.rc` > /dev/null 2> /dev/null
  else
   echo "Your already running ssh-agent!"
   exit 1
fi

add-key.rc: Used to just get the ssh-add command off and call screen

source ~/.bashrc
ssh-add
screen bash --init-file ~/bin/screen-start.rc


screen-start.rc: Execute all the screen's with title names

screen -t Sev1 2 ssh server1
screen -t Sev2 3 ssh server2
screen -t Sev3 4 ssh server3
screen -t IRC 1 irssi



And this would in sum load my ssh-agent bash, ssh-add, then open up all the screen sessions with proper titles and not have to enter my password more than once. Of course if you always load your ssh-agent, you can skip that part.

Please tell me someone has a better solution to this sort of situation. Like some cool way to start new screens inside of a detached session? Some way of making sure they spawn from the first bash shell with ssh-keys already loaded?

Or am I just crazy ? :-)

Danny-





reply via email to

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