If GNU screen already exists, reattach to it, else create it
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm trying to do this: if a GNU screen named worker
already exists, then reattach to it, else create it by starting python example.py
.
I tried:
if [ls /var/run/screen/S-root/ |grep -Fxq worker] then screen -r worker else cd /home/www/example/; screen -S worker python example.py fi
but it doesn't seem to work.
Is there something wrong in the syntax?
bash gnu-screen
add a comment |Â
up vote
0
down vote
favorite
I'm trying to do this: if a GNU screen named worker
already exists, then reattach to it, else create it by starting python example.py
.
I tried:
if [ls /var/run/screen/S-root/ |grep -Fxq worker] then screen -r worker else cd /home/www/example/; screen -S worker python example.py fi
but it doesn't seem to work.
Is there something wrong in the syntax?
bash gnu-screen
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to do this: if a GNU screen named worker
already exists, then reattach to it, else create it by starting python example.py
.
I tried:
if [ls /var/run/screen/S-root/ |grep -Fxq worker] then screen -r worker else cd /home/www/example/; screen -S worker python example.py fi
but it doesn't seem to work.
Is there something wrong in the syntax?
bash gnu-screen
I'm trying to do this: if a GNU screen named worker
already exists, then reattach to it, else create it by starting python example.py
.
I tried:
if [ls /var/run/screen/S-root/ |grep -Fxq worker] then screen -r worker else cd /home/www/example/; screen -S worker python example.py fi
but it doesn't seem to work.
Is there something wrong in the syntax?
bash gnu-screen
asked Apr 18 at 19:58
Basj
6031731
6031731
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20
add a comment |Â
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
It makes more sense to use screen -ls
or
screen -S worker -x || cd /home/www/example; screen -S worker python example.py;
But the errors in your code are
the unnecessary
[
(which would have needed spaces around it)if [ls /var/run/screen/S-root/ |grep -Fxq worker]
must be
if ls /var/run/screen/S-root/ | grep -Fxq worker
the missing
;
/ newline beforethen
|grep -Fxq worker] then
must be
| grep -Fxq worker; then
the missing
;
/ newline beforeelse
then screen -r worker else
must be
then screen -r worker; else
the missing
;
/ newline beforefi
python example.py fi
must be
python example.py; fi
Thanks a lot, your solutionscreen -S worker -x || ...
works fine. And I learnt about the missing;
+ unncessary[
, thanks as well!
â Basj
Apr 18 at 20:37
1
@Basj I use that every day because I startscreen
as root with the config file of my normal user account.
â Hauke Laging
Apr 18 at 20:41
Also my-Fxq
was wrong.if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.
â Basj
Apr 18 at 20:42
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
It makes more sense to use screen -ls
or
screen -S worker -x || cd /home/www/example; screen -S worker python example.py;
But the errors in your code are
the unnecessary
[
(which would have needed spaces around it)if [ls /var/run/screen/S-root/ |grep -Fxq worker]
must be
if ls /var/run/screen/S-root/ | grep -Fxq worker
the missing
;
/ newline beforethen
|grep -Fxq worker] then
must be
| grep -Fxq worker; then
the missing
;
/ newline beforeelse
then screen -r worker else
must be
then screen -r worker; else
the missing
;
/ newline beforefi
python example.py fi
must be
python example.py; fi
Thanks a lot, your solutionscreen -S worker -x || ...
works fine. And I learnt about the missing;
+ unncessary[
, thanks as well!
â Basj
Apr 18 at 20:37
1
@Basj I use that every day because I startscreen
as root with the config file of my normal user account.
â Hauke Laging
Apr 18 at 20:41
Also my-Fxq
was wrong.if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.
â Basj
Apr 18 at 20:42
add a comment |Â
up vote
2
down vote
accepted
It makes more sense to use screen -ls
or
screen -S worker -x || cd /home/www/example; screen -S worker python example.py;
But the errors in your code are
the unnecessary
[
(which would have needed spaces around it)if [ls /var/run/screen/S-root/ |grep -Fxq worker]
must be
if ls /var/run/screen/S-root/ | grep -Fxq worker
the missing
;
/ newline beforethen
|grep -Fxq worker] then
must be
| grep -Fxq worker; then
the missing
;
/ newline beforeelse
then screen -r worker else
must be
then screen -r worker; else
the missing
;
/ newline beforefi
python example.py fi
must be
python example.py; fi
Thanks a lot, your solutionscreen -S worker -x || ...
works fine. And I learnt about the missing;
+ unncessary[
, thanks as well!
â Basj
Apr 18 at 20:37
1
@Basj I use that every day because I startscreen
as root with the config file of my normal user account.
â Hauke Laging
Apr 18 at 20:41
Also my-Fxq
was wrong.if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.
â Basj
Apr 18 at 20:42
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
It makes more sense to use screen -ls
or
screen -S worker -x || cd /home/www/example; screen -S worker python example.py;
But the errors in your code are
the unnecessary
[
(which would have needed spaces around it)if [ls /var/run/screen/S-root/ |grep -Fxq worker]
must be
if ls /var/run/screen/S-root/ | grep -Fxq worker
the missing
;
/ newline beforethen
|grep -Fxq worker] then
must be
| grep -Fxq worker; then
the missing
;
/ newline beforeelse
then screen -r worker else
must be
then screen -r worker; else
the missing
;
/ newline beforefi
python example.py fi
must be
python example.py; fi
It makes more sense to use screen -ls
or
screen -S worker -x || cd /home/www/example; screen -S worker python example.py;
But the errors in your code are
the unnecessary
[
(which would have needed spaces around it)if [ls /var/run/screen/S-root/ |grep -Fxq worker]
must be
if ls /var/run/screen/S-root/ | grep -Fxq worker
the missing
;
/ newline beforethen
|grep -Fxq worker] then
must be
| grep -Fxq worker; then
the missing
;
/ newline beforeelse
then screen -r worker else
must be
then screen -r worker; else
the missing
;
/ newline beforefi
python example.py fi
must be
python example.py; fi
answered Apr 18 at 20:25
Hauke Laging
53.2k1282130
53.2k1282130
Thanks a lot, your solutionscreen -S worker -x || ...
works fine. And I learnt about the missing;
+ unncessary[
, thanks as well!
â Basj
Apr 18 at 20:37
1
@Basj I use that every day because I startscreen
as root with the config file of my normal user account.
â Hauke Laging
Apr 18 at 20:41
Also my-Fxq
was wrong.if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.
â Basj
Apr 18 at 20:42
add a comment |Â
Thanks a lot, your solutionscreen -S worker -x || ...
works fine. And I learnt about the missing;
+ unncessary[
, thanks as well!
â Basj
Apr 18 at 20:37
1
@Basj I use that every day because I startscreen
as root with the config file of my normal user account.
â Hauke Laging
Apr 18 at 20:41
Also my-Fxq
was wrong.if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.
â Basj
Apr 18 at 20:42
Thanks a lot, your solution
screen -S worker -x || ...
works fine. And I learnt about the missing ;
+ unncessary [
, thanks as well!â Basj
Apr 18 at 20:37
Thanks a lot, your solution
screen -S worker -x || ...
works fine. And I learnt about the missing ;
+ unncessary [
, thanks as well!â Basj
Apr 18 at 20:37
1
1
@Basj I use that every day because I start
screen
as root with the config file of my normal user account.â Hauke Laging
Apr 18 at 20:41
@Basj I use that every day because I start
screen
as root with the config file of my normal user account.â Hauke Laging
Apr 18 at 20:41
Also my
-Fxq
was wrong. if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.â Basj
Apr 18 at 20:42
Also my
-Fxq
was wrong. if screen -ls |grep -Fq worker; then screen -r worker; else cd /home/www/example/; screen -S worker python example.py; fi
is correct.â Basj
Apr 18 at 20:42
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438585%2fif-gnu-screen-already-exists-reattach-to-it-else-create-it%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What do you mean by this screen -S worker python example.py, you want to create a session and run python example.py in it ?
â Bharat
Apr 18 at 20:19
@Bharat yes, if the session is not already running and detached.
â Basj
Apr 18 at 20:20