0

I want to check whether the script test.sh is running or not in the screen(GNU screen) named testscreen.
Need to do this job for many servers, so, want to do through ssh remotely.

for serverid in {1..100}; do ssh root@server${serverid} "command"

How can I make command to check the script test.sh is running or not in the screen named testscreen?

1

1 Answer 1

1

using

screen -Q windows

you can list the windows including the started commands in each.

So, to inspect a specific session

screen -S testscreen -Q windows

To test for the presence of a specific command test.sh:

screen -S testscreen -Q windows | grep -E '^[[:digit:]]+[[:space:]]+test\.sh$'

(note that this is the window title)

running this via ssh just works:

for serverid in {1..100}; do 
  ssh root@server${serverid} screen -S testscreen -Q windows \
    | grep -q -E '^[[:digit:]]+[[:space:]]+test\.sh$' \
    && echo "command running!" \
    || echo "not running!"
done
2
  • Just wondering - why not grep -q instead of redirecting stdout to /dev/null? Is it not not a standard flag?
    – aviro
    Jun 1, 2023 at 11:35
  • @aviro honestly, for me it's just "muscle memory"; you're right -q would be more elegant. I don't think it's non-standard (and that wouldn't matter much – on a machine with GNU screen, having GNU coreutils feels rather likely). Jun 1, 2023 at 11:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .