How can i create a screen
in detached mode only if it doesn't exist?
This creates a screen named name in detached mode but will create duplicates
screen -dmS name command
This creates a screen only if it doesn't exist but not detached
screen -dRms name command
How do i combine both? I need to create multiple screens in a batch file so reattaching is not convenient. I want to use the batch file to "restart" screens that have died for various reasons but leave the already running ones intact.
I've just stumbled over this issue and solved it like this:
In my case, the screen session name I'm interested in is
'activity'
(for my activity tracker project).Python Script
does_screen_session_exist.py
Python 3.4+; no dependencies:
Bash script
The easiest one-line solution is to use flock with screen:
try this:
it will list only one session. Hope it would help.