May be I wasn't clear enough. The script runs as root all the time. I just need to run the few steps as a given user and get back to root. Theses steps involve populating a cron tab. I'm looking for the best way of doing that. An idea that I was thinking of was to do this in a separate thread, then this approach isn't Posix compliant and I'm not sure if the whole process doesn't get the same UID (the script runs under Solaris).
Any...
User Profile
Collapse
-
Oops! Correcting indentation:
Code:import os try: if os.name == 'posix': import pwd pw = pwd.getpwnam(user) uid = pw.pw_uid os.setuid(uid) else: # Do something useful here except: return 1 # Error finally: # Put back root user... os.setuid(0)Leave a comment:
-
switch back and forth from root to a user
Hi there,
I looked around and couldn't find an answer to this question (and I'm now wondering is there is one :-)
I have a piece of code in which I need to switch from root to a particular user, run the command as this user and would like to return to root. I don't want to use, if possible at all, "su".
Here is the snippet code that is run as root initially:
...Code:import os try:
No activity results to display
Show More
Leave a comment: