View previous topic :: View next topic |
Author |
Message |
szatox Veteran

Joined: 27 Aug 2013 Posts: 1995
|
Posted: Sat Jul 25, 2020 9:05 pm Post subject: |
|
|
Quote: | I did try it once (not super intensively), and my problem was that I was forgetting that I am in screen session and that there are some other sessions in the same terminal window. So after some time
there were several orphaned screens that I forgot about. So I returned to 'one window - one session' workflow. Perhaps requires some practice. |
Just use `screen -DR`
It will forcefully re-attach to an existing session if it exists and start a new one if it doesn't.
Also, screen is super useful with SSH. I like running it as `ssh myuser@remote.host -t screen -DR`, particularly handy when working over an unstable radio link (though wireguard too can circumvent dropping links to some extent - like in before your TCP connection times out). |
|
Back to top |
|
 |
cboldt l33t


Joined: 24 Aug 2005 Posts: 911
|
Posted: Sun Jul 26, 2020 12:40 pm Post subject: |
|
|
I use a script called "attach" that will find an existing screen session if one so named exists, otherwise create one with that name.
The script takes advantage of screen ability to open using other than default config file. I only have a few sessions, one for email, one for a handful of occassionally used thinks, mostly alsamixer but also `mc`. The command `attach email` opens a screen session with no split window, Alt-0 is a `tailf` of procmail delivery log, Alt-1 is alpine (started manually), and Alt-2 is a shell. One instance of this runs on the LAN. From any machine I can ssh to the email server and run `attach email` to get that working environment. It runs all the time.
Code: | #!/bin/bash
# ~/bin/attach
# Finds screen session and, if it exists, reattaches to it
# If screen session does not exist, start a new one
# When starting a new screen session, use .screenrc-$1 if it exists
# alias screen-misc='TERM=xterm screen -x `screen -ls | grep misc-Client | cut -f2`'
if [ "$TERM" = "screen" ]; then
echo You are already in a SCREEN session ...
echo I will not attach a screen session from within screen
exit
elif [ "$1" == "" ]; then
echo You must supply an argument.
screen -ls
exit
fi
screen -ls | grep "Remove dead screens" && screen -wipe
if [ -z "`screen -ls | grep $1-Client`" ]; then
# echo There is no screen session known as \"$1-Client\"
if [ -f ~/.screenrc-$1 ]; then
# echo -ne "\033]0;screen-$1\007"
# Start new screen session with .screenrc-$1 configuration
exec screen -c .screenrc-$1 -S $1-Client
exit
else
# echo -ne "\033]0;screen-$1\007"
# Start new screen session with .screenrc configuration
exec screen -S $1-Client
exit
fi
else
# Attach to existing screen session
exec screen -x $1-Client
fi |
I also use screen to get an equivalent of multi-tabbed lynx browser, but without the tabs. Alt-1, Alt-2, Alt-3, etc. to jump between instances of lynx. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|