Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Q on file ownership
#1
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
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get File Ownership under Windows newatpython 6 16,314 Mar-24-2017, 01:18 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020