How to find how many windows are opened in GNU screen

gnugnu-screenscriptingwindow

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.

Best Answer

screen -Q windows

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

Related Question