Reputation: 33
I have a bash script that runs among other things a python script every time the system is booted.
Part of that python script is supposed to be logging to a log file (mostly used for debug purposes). The script runs fine whether I run it manually or through the bash script.
The issue is that when I run it through the bash script the Python script does not create the log file nor log any of the debugging LOGGING commands I have in the script.
I am assuming this is a permission issue within the directory.
I'm calling my script from /etc/rc.local
sudo /home/user/python_scripts/go.sh &
Here is the python line in my bash script (go.sh)..
#!/bin/sh
python /home/user/python_scripts/go.py
Inside of my python code I am logging using the following (which when I run manually places the log file in the python_scripts directory:
import logging
daily_log = 'log-' + str(time.strftime("%m-%d-%y")) + '.log'
logging.basicConfig(format='%(asctime)s (%(levelname)s) - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename=daily_log,level=logging.DEBUG)
logging.debug(' Debug Message - Error 1241')
Upvotes: 1
Views: 3283
Reputation: 215
Try using the whole path to the log file. It will log into the working directory when the script is run.
If you run from /home/user/python_scripts/ it will put the file there.
If you run from /home/ the file will be in your home directory.
Upvotes: 2