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?
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With