3 made it clearer that the shells belong to "appuser".
source | link

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with appuser's $SHELL running in them, running as user "appuser".
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3 sudo -u appuser -i
screen -c /dev/null -S mySession -X screen -t tab6 sudo -u appuser -i

# as root, you could use `su - appuser`, instead of sudo but that
# would ask for a password if this is run as non-root user.  sudo
# can be configured to not ask for a password if required.   

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to theappuser's shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with appuser's $SHELL running in them.
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3 sudo -u appuser -i
screen -c /dev/null -S mySession -X screen -t tab6 sudo -u appuser -i

# as root, you could use `su - appuser`, instead of sudo but that
# would ask for a password if this is run as non-root user.  sudo
# can be configured to not ask for a password if required.   

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to the shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with appuser's $SHELL running in them, running as user "appuser".
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3 sudo -u appuser -i
screen -c /dev/null -S mySession -X screen -t tab6 sudo -u appuser -i

# as root, you could use `su - appuser`, instead of sudo but that
# would ask for a password if this is run as non-root user.  sudo
# can be configured to not ask for a password if required.   

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to appuser's shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

2 added 255 characters in body
source | link

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with appuser's $SHELL running in them.
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3 sudo -u appuser -i
screen -c /dev/null -S mySession -X screen -t tab6 sudo -u appuser -i

# as root, you could use `su - appuser`, instead of sudo but that
# would ask for a password if this is run as non-root user.  sudo
# can be configured to not ask for a password if required.   

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to the shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with $SHELL running in them.
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3
screen -c /dev/null -S mySession -X screen -t tab6

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to the shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with appuser's $SHELL running in them.
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3 sudo -u appuser -i
screen -c /dev/null -S mySession -X screen -t tab6 sudo -u appuser -i

# as root, you could use `su - appuser`, instead of sudo but that
# would ask for a password if this is run as non-root user.  sudo
# can be configured to not ask for a password if required.   

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to the shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc

1
source | link

You need to create the tabs first, and then tell screen to run something in them, using -X stuff.

For example:

#!/bin/bash

# start a new detached screen, create windows named tab3 and tab6
# with $SHELL running in them.
screen -c /dev/null -d -m -S mySession
screen -c /dev/null -S mySession -X screen -t tab3
screen -c /dev/null -S mySession -X screen -t tab6

# run some programs in the already-created tab3 and tab6
# using screen's "stuff" command.
screen -c /dev/null -S mySession -p tab3 -X stuff $'top\n'
screen -c /dev/null -S mySession -p tab6 -X stuff $'htop\n'

You can attach to that screen with, e.g., screen -S mySession -d -RR. If you quit from either top or htop in their respective tabs, those tabs will NOT close, they'll return to the shell prompt.

I'm using -c /dev/null here to stop screen from reading my ~/.screenrc, which creates a bunch of tabs and sets everything up as I want it. Or used to want it, I switched to tmux about a year ago after using screen for decades.

Another way to do this is to create a new screenrc file with the required screen and stuff commands in it, and then just run screen -c /path/to/newscreenrc