Configuring screen to automatically create specific window panes and launch scripts/commands when starting...

Category: Software and Systems Engineering
Author: Sean O'Donnell
Wed, Oct. 22nd, 2014 @ 17:17:44 (MDT)

The following example is intended to illustrate the simple way to launch multiple screen panes and execute multiple commands/scripts automatically when you start a 'screen' session. This is a huge time-saver for many tasks.

In this example, we will open (7) panes, each tasked with a specific command/script to be executed when the screen pane is created. The following configuration should be saved to a .screenrc file in your $HOME directory (i.e. ~/.screenrc)..

# ~/.screenrc
# Open multiple screens and runs specific
# commands/scripts automatically when screen starts.
startup_message off
term rxvt
hardstatus on
hardstatus alwayslastline

screen -t screens
0 bash
screen -t screen1
1 sh -c "cd ~/workspace; ls -la"
screen -t screen1
2 sh -c "sudo htop"
screen -t screen1
3 sh -c "sudo top"
screen -t screen1
4 sh -c "sudo iptstate"
screen -t screen1
5 sh -c "sudo netstat -taupnc"
screen -t screen1
6 sh -c "sudo tail -f /var/log/httpd/error_log"
screen -t screen1
7 sh -c "irssi"

To instantiate your screen session and automatically kick off the sub-pane processes, you simply use the following command:

You can then detach and reattach your screen session as needed, and all the sub-pane processes will continue to run on the system. This is extremely useful when interacting with local or remote terminals on a linux/unix-based OS.
Keep in-mind that each pane will automatically terminate if you stop the default process that was executed when the pane was created, or if the command/script is not found upon execution attempt.

Copyleft (<) 1998-2019