0

I have kept my python script "myscript.py" in /etc/rc.local as below, and run in background. I have kept few print statements inside the script, which print some values and error codes etc.

/etc/rc.local------
....
sudo python /home/pi/myscript.py &

My questions is while running the python script as above, will the "print" statements inside the script be automatically redirected to the "log" files?

Note: I have not redirected to any log file from my script.

I have now kept my Raspberry PI in remote location where I can not access it for a week. That is the reason I can not check the log files (if any).

Thanks,

  • 1
    You don't need to use sudo here because rc.local is already run as root. – John Hawthorne Apr 24 '18 at 18:07
1

This is not really specific to the Raspberry PI but I'll answer it anyway.

By default, no, the output from commands in rc.local will not be logged but there are many ways to achieve that. One simple way is to log the output from rc.local to some file by inserting the following commands at the start of rc.local:

exec 2> /var/log/rc.local.log
exec 1>&2

That will send stdout and stderr to the file /var/log/rc.local.log

1

It is unlikely that any output from the script will be logged into the system log files in /var/log/*, unless you can have your python script make OS-level calls to "logger", eg logger "myscript.py is running". This will allow your script to write status messages to the /var/log/messages file and you'll be able to check on it remotely.

See here for more details.

0

I would advice to log stuff into syslog. https://docs.python.org/2/library/syslog.html

Your Answer

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

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