LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-28-2016, 09:27 PM   #1
keirvt
Member
 
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 155

Rep: Reputation: 17
multiple screens and switching


I have a group of users using text based terminals and often use different menus with various configurations and environment variables. (Its an old system still using text based terminals)

I think one way to get an easy swap facility is to use the Unix "screen" command in a script that sets them up so they can swap between a menu configurations using ctrl-A <number>

To do this I wrote a script that might set them up in this way

Code:
#!/bin/bash
screen -d -m -S "main" # Parent window

# Just echo main on screen 
screen -S main -p 0 -X stuff "echo main
"

for i in 1 2 3 4 5
do
  echo create screen $i
  screen -S main -X stuff "screen -d -m -S $i
"
done
screen -r main
This creates a parent screen and then sends a create screen command to be executed in that parent screen. This creates the screens but switching between them can only be done with the command "screen -R n" where n is the name of the screen.

It should be possible using ctrl-A n but I can't see how to get that to work.
Any thoughts please?
 
Old 11-29-2016, 03:46 PM   #2
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
Quote:
Originally Posted by keirvt View Post
I have a group of users using text based terminals and often use different menus with various configurations and environment variables. (Its an old system still using text based terminals)

I think one way to get an easy swap facility is to use the Unix "screen" command in a script that sets them up so they can swap between a menu configurations using ctrl-A <number>

To do this I wrote a script that might set them up in this way

Code:
#!/bin/bash
screen -d -m -S "main" # Parent window

# Just echo main on screen 
screen -S main -p 0 -X stuff "echo main
"

for i in 1 2 3 4 5
do
  echo create screen $i
  screen -S main -X stuff "screen -d -m -S $i
"
done
screen -r main
This creates a parent screen and then sends a create screen command to be executed in that parent screen. This creates the screens but switching between them can only be done with the command "screen -R n" where n is the name of the screen.

It should be possible using ctrl-A n but I can't see how to get that to work.
Any thoughts please?
I believe the 'Ctrl-Alt-<N>' is an Xorg function? Would 'sudo chvt <N>' work for you?
 
Old 11-30-2016, 01:40 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,681
Blog Entries: 3

Rep: Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920
You're close. The following should work to create multiple windows in a single "screen" session:

Code:
screen -d -m -S main;    # create main session
screen -S main -p 0 -X stuff "echo this is window 0"

for i in {1..5}; do

  echo creating window $i in session "main"
  screen -S main -X screen $i

done

screen -r -S main
The last line will automatically connect to the last window in the session. Then you can do ctrl-A n to get to window n. If you want to go to a specific window, then use -p. The following goes to window 0

Code:
screen -r -S main -p 0
Though I started with "screen" back in the day, I find "tmux" easier to work with and have almost entirely moved over to it instead.
 
2 members found this post helpful.
Old 11-30-2016, 11:16 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,681
Blog Entries: 3

Rep: Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920
I should clarify this key line because it appears it was the point of confusion:

Code:
  screen -S main -X screen $i
The part after -X is an internal command and has the misfortune through bad UI design of consisting of the string "screen" which happens to be the current name of the main program. The two are not related, even though both strings appear the same. As seen above, "stuff" is another internal command that can be used and there are many more as seen in the manual page in the section "customization"

If you were to use "mv" to rename /usr/bin/screen to /usr/bin/okra you would have the following instead:

Code:
  okra -S main -X screen $i
 
1 members found this post helpful.
Old 11-30-2016, 03:38 PM   #5
keirvt
Member
 
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 155

Original Poster
Rep: Reputation: 17
Screen idiosyncrasies

Thank you all for those comments.
That worked for me.

A number of post suggested that tmux is better option and Turbocapitalist's comments seem to reinforce that.
Still the Devil you have got to know and all that.

One small problem is that if you want to find what screen you are in
echo $STY will tell you. With the solution below, using ctrl-A n the STY variable remains a "main"

Anyway I am happy
 
1 members found this post helpful.
Old 12-01-2016, 12:54 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,681
Blog Entries: 3

Rep: Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920
Glad it is working.

Quote:
Originally Posted by keirvt View Post
One small problem is that if you want to find what screen you are in
echo $STY will tell you. With the solution below, using ctrl-A n the STY variable remains a "main"
$STY will remain the same for all the windows in a session, but "screen" seems to set the environment variable $WINDOW differently for each window. So you could use that if you need your programs or scripts to differentiate between windows.
 
Old 12-19-2016, 03:24 PM   #7
ahedler
Member
 
Registered: Oct 2005
Location: A safe distance from Detroit
Distribution: SuSE 10.0, Knoppix
Posts: 99

Rep: Reputation: 17
If you create a .screenrc file containing 'caption always' on the first line, when you invoke screen you will get a status bar at the bottom of the screen with the number and title of the window. You can change the title on each window with '^A A' and change the title to what you want.

While you are in screen, you can change from one window to another with '^A <n>' where <n> is the number of the window you want to go to, or you can use 'p' and 'n' in place of the window number to go to the previous and next windows in the sequence. Of course, '^A ^A' switches back to the last window you were in. '^A w' will list the windows and their titles in the status bar at the bottom.

I believe there is also a way to preconfigure the windows and their titles in the .screenrc file, but I haven't played with that so far.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xming and switching screens jdenmon Linux - Software 0 08-29-2012 01:09 PM
switching screens eagle576 Linux - Software 6 07-20-2011 05:00 PM
Switching Screens FredGSanford Linux - General 1 03-04-2011 05:23 PM
Managing multiple screens: redirecting video output and switching between screens simopal6 Linux - Hardware 2 11-13-2007 06:08 AM
Fast User Switching or Multiple X login screens - How? suslik Slackware 10 08-31-2004 07:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration