os.chown()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Colannino

    #1

    os.chown()

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

    os.chown('filen ame', '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

  • Mike Meyer

    #2
    Re: os.chown()

    James Colannino <james@colannin o.org> writes:
    [color=blue]
    > Hey everyone. I tried to use os.chown() in the following manner:
    >
    > os.chown('filen ame', '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?[/color]

    You want pwd.getpwnam and grp.getgrnam.

    <mike
    --
    Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

    Comment

    • James Colannino

      #3
      Re: os.chown()

      Mike Meyer wrote:
      [color=blue]
      >You want pwd.getpwnam and grp.getgrnam.
      >
      >[/color]

      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

      Comment

      • Tim Roberts

        #4
        Re: os.chown()

        James Colannino <james@colannin o.org> wrote:[color=blue]
        >
        >Hey everyone. I tried to use os.chown() in the following manner:
        >
        >os.chown('file name', '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?[/color]

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

        Are you doing this as root? The chown function is usually restricted to
        root.
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...