os.chown()

J

James Colannino

Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way for
me to change ownership based on the name instead of the number? Perhaps
there's a function that will let me lookup the uid from the username,
and the gid from the groupname?

Thanks :)

James

--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment
 
M

Mike Meyer

James Colannino said:
Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way
for me to change ownership based on the name instead of the number?
Perhaps there's a function that will let me lookup the uid from the
username, and the gid from the groupname?

You want pwd.getpwnam and grp.getgrnam.

<mike
 
T

Tim Roberts

James Colannino said:
Hey everyone. I tried to use os.chown() in the following manner:

os.chown('filename', 'username', 'groupname')

I got an error, and when I googled for this function I realized that I
must pass the numerical uid and gid. My question is, is there a way for
me to change ownership based on the name instead of the number? Perhaps
there's a function that will let me lookup the uid from the username,
and the gid from the groupname?

One way is:
os.system( 'chown username:groupname filename')

Are you doing this as root? The chown function is usually restricted to
root.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top