script to detach screen and close down ssh connection

Soldato
Joined
3 Dec 2002
Posts
4,033
Location
Groovin' @ the disco
Hi

I've got my .bashrc to automatically start a screen session or join the last screen session, so I can have processes running and no have to keep the connection live.

I'm been trying to setup a script to detach the screen session and close down the ssh connection automatially.

To detach, I can use 'screen -d <screen name>, but I can't get it to close down the connection correclty.

The way I've got it at the moment, is that I've placed and y/n prompt in the main bashrc script after the screen command, so when I detatch it prompts me of I want to keep the connection live. and if I press anything but 'y' it runs the exit command.

Is there any suggestions to make this better? I would prefer to be able to alias 'exit' command to a script that will detatch the screen and then exit the ssh connection.

Thanks in advance.
 
I've sorted it...
its just needs a capital D rather than a lower case d...
so in my .bashrc I have

Code:
if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
  STARTED_SCREEN=1 ; export STARTED_SCREEN
  screen -RR -S main || echo "Screen failed! continuing with normal bash startu$
fi

to start the screen session called main automatically.

and

Code:
alias exit='screen -D main'

so that when I type exit now, rather than exit the screen app, it detaches from screen session and exits from ssh.

When I ssh back in to the machine it will continue from the same location.

:D
 
Back
Top Bottom