Question

I have multiple task to be done on each window of the screen. I need to automate it with some simple script. Any help on this will be appreciated.

               Start a Screen named "XYZ" with window "1"
               Start a another window "2"
               Run a particular command on the window "1"
               Run a particular command on the window "2"

         This can continue for multiple windows,
         needed  simple API's to achieve this.
Was it helpful?

Solution

I figured from the screen man page that , we can send commands to particular screen and window, using the screen with -X switch.

  '-X' - Send the specified command to a running screen session. 
   You can use the -d or -r option to tell screen to look only for attached or 
   detached screen sessions. Note that this command doesn't work if the session 
   is password protected.'
   Source:  http://www.gnu.org/software/screen/manual/screen.html

I have just wrapped the screen command in python API's , so just writing a python script suffices my work to automate.

       For creating a screen, creating a window and then sending commands.

      `https://github.com/innosam/screenapi`

OTHER TIPS

You may look at tmux as an alternative to screen. Among other things it's control mode allows applications to communicate with tmux using a simple text-only protocol.

Well you can try as below:

# Default screens
screen -t shell1      0
screen -t shell2      1
screen -t server      2       ssh me@myserver

Please refer to this redhat guide for GNU screen

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top