Q on file ownership - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Q on file ownership (/thread-23424.html) |
Q on file ownership - ebolisa - Dec-29-2019 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 RE: Q on file ownership - micseydel - Dec-29-2019 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. RE: Q on file ownership - ebolisa - Jan-02-2020 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. |