I'm having a bit of trouble with GNU's screen. What I want to do is this (from cron):

If a screen session named cron exists, add a new window to the session and launch a process in it (but do not attach to the session). Otherwise, create a new session called cron and launch the process in it (again, do not attach). If possible, all of this should be done using just one "screen" command.

I've already tried a bit but haven't come to a solution that satisfies all of my needs:

screen -S cron -dRRm screen ping example.com
screen -S cron -X screen ping example.com

Is there something I have missed?

link|improve this question
feedback

1 Answer

I don't think that you can do this in one command, but this should do what you want:

screen -ls cron | grep -q '(\w*tached)' >&- || screen -dmS cron
screen -S cron -X screen ping example.com
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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