Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > os.chown()

Reply
Thread Tools

os.chown()

 
 
James Colannino
Guest
Posts: n/a
 
      11-11-2005
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

 
Reply With Quote
 
 
 
 
Mike Meyer
Guest
Posts: n/a
 
      11-11-2005
James Colannino <(E-Mail Removed)> writes:

> 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
--
Mike Meyer <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
 
 
 
James Colannino
Guest
Posts: n/a
 
      11-11-2005
Mike Meyer wrote:

>You want pwd.getpwnam and grp.getgrnam.
>
>


Thanks. Hope my newbie questions haven't gotten on anybody's nerves yet

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

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      11-13-2005
James Colannino <(E-Mail Removed)> wrote:
>
>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.
--
- Tim Roberts, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments