0

I'm trying discover if any linux screen session is running. Currently, I have the code for only a specific screen by name, but I want discover if any screen session is running. Can you help me?

screen -list | grep "SESSİON NAME" && echo "Active Program" || echo "Passive Program"

How can I update this code above to match all screens running?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
mitrik
  • 21
  • 6
  • What is the output of `screen -list` when no sessions are active and when some sessions are active? – KamilCuk Jul 13 '19 at 09:18
  • No active: No Sockets found in /run/screen/S-root. // Active: There is a screen on: 10549.pts-0.database2 (07/13/2019 09:21:20 AM) (Attached) 1 Socket in /run/screen/S-root. – mitrik Jul 13 '19 at 09:21
  • It's just a example, but I want only discover if there are screen sessions running on my server – mitrik Jul 13 '19 at 09:22
  • Please edit your question and include the output in your post. – KamilCuk Jul 13 '19 at 09:28
  • Possible duplicate of [How to list running screen sessions?](https://stackoverflow.com/q/537942/608639), [How can I list screen sessions by name?](https://stackoverflow.com/q/3680607/608639), [How to list all users that have terminal sessions, including screen sessions?](https://superuser.com/q/352752/173513), etc. – jww Jul 13 '19 at 14:30

1 Answers1

1

Just grep for the proper string:

if screen -list | grep "No active:"; then echo "No active Program"; else echo "There is an active Program"; fi
KamilCuk
  • 120,984
  • 8
  • 59
  • 111