Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

starting script in screen

I want to start a python script within screen from a script. I tried this

screen -dmS gateway_monitor;screen -r gateway_monitor -p 0 -X '/usr/bin/python /root/Gateway.py'

but if I reattach to the screen afterwards, it's just empty and looks like nothing has been executed at all. Any clues why this is or how I get achieved what I want?

like image 764
stdcerr Avatar asked Sep 27 '12 23:09

stdcerr


People also ask

How do I boot a script?

On Windows, the simplest way of running a program at startup is to place an executable file in the Startup folder. All the programs that are in this folder will be executed automatically when the computer opens. You can open this folder more easily by pressing WINDOWS KEY + R and then copying this text shell:startup .


1 Answers

You can use:

screen -dm bash -c 'python your_script.py'

If you need several commands, use ;:

screen -dm bash -c 'source ~/.bash_profile; python your_script.py'

Documentation:

https://www.gnu.org/software/screen/manual/screen.html:

-d -m: Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

http://linux.about.com/library/cmd/blcmdl1_sh.htm :

-c string: If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

like image 173
Franck Dernoncourt Avatar answered Nov 16 '22 01:11

Franck Dernoncourt