Search code examples
pythonlinuxautomationgnu-screen

How to automate GNU screen with multiple windows


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.

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`