Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?
My script
- scans some folders and files to check if it can do the job
- makes some changes in /etc/...
- creates a folder and files that should be owned by the user who ran the script
(1) can be done as a normal user. I can do (2) by sudoing the script, but then the folder and files in (3) will be root's.
The issue is that I use a lot of os.makedirs, os.symlink, etc, which stops me from making it runnable by a normal user.
Tanks 2 all for suggestions
The solution so far is:
# do all in sudo
os.chown(folder, int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID')))
thanks to gnibbler for hint.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…