I want to be able to start a python script when I boot, but I want to be able to see lines which have been printed during the program. I have been able to put the line "sudo python /path/to/file.py" into /etc/rc.local but of course I can't then see the output.

Is it possible to put some kind of line in there to start the program in a screen terminal and which I can then access when I SSH in? - maybe something along the lines of...

screen sudo python /path/to/file.py
  • I'd suggest you write whatever to a file in /tmp instead and then have ssh, etc. use it as a greeting (dunno if ssh has greetings, I'd think the ascii artists of the world would already have beat down doors about that). Put another way, you might want to consider the XY problem here. – goldilocks Apr 3 '16 at 16:19
  • 1
    Do you need sudo if you start the script from /etc/rc.local? Isn't it run by root? – Lucas Apr 4 '16 at 7:00

If you wish to use screen, use something like:

screen -dmS yourscreenname sudo python /path/to/file.py

from rc.local to run your program on detached screen. Next, after boot you can attach to it by

screen -r yourscreenname 

from root account.

Alternativly - if you only wish to have logs from your program - maybe simpler is redirect output to syslog? for example:

sudo python /path/to/file.py|logger

If you wish also redirect standard errror output, don't forget about 2>&1:

sudo python /path/to/file.py 2>&1 |logger
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy