1

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')
4
  • post the part where you write to the file. Commented Feb 13, 2014 at 18:29
  • How is the bash script run? Does the Python script write to a specific file, or just to standard error and/or output (which it inherits from the bash script, and could be different from when you run the Python manually)? Commented Feb 13, 2014 at 18:32
  • updated with more information... Commented Feb 13, 2014 at 18:59
  • Have you checked out the ans to this question? Specifically, setting the logger to logging.StreamHandler(sys.stdout) Commented Feb 13, 2014 at 19:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.