Python Forum

Full Version: Q on file ownership
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Why the generated log file has root ownership and not user's?

TIA

fileLog = '/home/pi/mylogs.log'

# Log messages should be time stamped
def timeStamp():
    t = time.time()
    s = datetime.fromtimestamp(t).strftime('%Y/%m/%d %H:%M:%S - ')
    return s

# Write messages in a standard format
def printMsg(s):
    log = open(fileLog, 'a+')
    log.write(timeStamp() + s + "\n")
    time.sleep(.1)
    log.close()
output:

Quote:-rw-r--r-- 1 root root 55 Dec 29 20:05 mylogs.log
You need to provide more detail - the code you've provided doesn't do anything except define functions, and you should tell us how you're running your scripts (e.g. are you using sudo?). We should have at least full instructions for reproducing the issue.
The .py file is excuted by a service using sudo thus .log file is saved as root. I just need to figure out how to run the .py service as user now. Thank you.