I am trying to automate my work flow. I have a script that opens individual window in screen for each IP in a list. Imagine setupscreen.sh <IP1> <IP2> .... After all windows are open, each sshs to the proper server and sets the title to hostname on that particular server. I keep window 0 as my utility window from where I execute other scripts. For example I send commands to all windows, loop over each window with 1 second interval, and so on. This is all good, but the problem is, I get the window count from my script when I create them. If I close a window, this is no longer accurate. The question is how can I get (through scripting) my window count and if possible the remaining windows indexes.

p.s. All clusters I need to login and perform tasks have screen and almost non of them have tmux and it's hustle to get it there.

  • Screen is no longer being actively developed, tmux offers a better solution and is still receiving updates. – Joe Sep 25 '15 at 17:31
  • The closest thing I'm aware of would be the windowlist command (Control-A w) – Jeff Schaller Sep 25 '15 at 17:36
  • @Joe I know this but it's not up to me. This is why I have the note on the bottom. – Lyubo Sep 25 '15 at 19:22
  • @JeffSchaller if I can only catch somehow the output of ctrl-a-w ( or better ctrl-a-") I'll be happy. – Lyubo Sep 25 '15 at 19:24

screen -Q windows

will print out your active screen windows with index & title.

  • This is pipe-able but you still would catch a pause in the shell script before it would output. Seems very strange to me. – Joe Sep 26 '15 at 3:05
  • On the machines I work with, screen is not compiled with -Q. – Lyubo Oct 29 '15 at 1:45
  • It is useful, but will not work in all cases. From documentation of the "windows" command: "If this list is too long to fit on the terminal's status line only the portion around the current window is displayed." So, you are not guaranteed the full list. – jwd Mar 23 '18 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.