Professional Web Applications Themes

ruby way to enumerate users - Ruby

Hi, exists there a preferred ruby way to enumerate the users names and directories? especially on linux...

  1. #1

    Default ruby way to enumerate users

    Hi,
    exists there a preferred ruby way to enumerate the
    users names and directories?


    especially on linux
    Robert Guest

  2. #2

    Default Re: ruby way to enumerate users


    "Robert K." <de> schrieb im Newsbeitrag
    news:401d3b89$0$24652$arcor-online.net... 

    Maybe something like this

    ruby -naF: -e 'printf "%s\t%s\n", $F[0], $F[5]' /etc/passwd

    robert

    Robert Guest

  3. #3

    Default Re: ruby way to enumerate users


    "Robert K." <de> schrieb im Newsbeitrag
    news:401d3b89$0$24652$arcor-online.net... 

    Maybe something like this

    ruby -naF: -e 'printf "%s\t%s\n", $F[0], $F[5]' /etc/passwd

    robert

    Robert Guest

  4. #4

    Default Re: ruby way to enumerate users



    Is this allways applicable? For example in an NIS+ env
    - that's why I'm asking.



    THX
    Robert Guest

  5. #5

    Default Re: ruby way to enumerate users

    On Sun, Feb 01, 2004 at 08:43:11PM +0100, Robert K. wrote: 
    >
    > Is this always applicable? For example in an NIS+ env
    > - that's why I'm asking.[/ref]

    Definitely not. NIS, NIS+, NetInfo, non-UNIX POSIX environments, . . .
    all sorts of different places the info could be. What is needed is a
    Ruby interface to the getpwent() family of system calls.
    I don't see any such thing in the standard library, RAA, or Ruby Forge;
    maybe I'm just not looking in the right place, or maybe you have just
    discovered your first module project! :)

    -Mark
    Mark Guest

  6. #6

    Default Re: ruby way to enumerate users


     

    Others: Is this the case?
    Do I have to or may I develope that module?
     
    Robert Guest

  7. #7

    Default Re: ruby way to enumerate users

    On Monday, February 2, 2004, 8:14:50 AM, Mark wrote:
     
    >>
    >> Is this always applicable? For example in an NIS+ env
    >> - that's why I'm asking.[/ref][/ref]
     

    require 'etc'

    (Should be in PickAxe, definitely in Nutshell.)

    Gavin




    Gavin Guest

  8. #8

    Default Re: ruby way to enumerate users

    Me> What is needed is a Ruby interface to the getpwent() family of system calls.
    Me> I don't see any such thing in the standard library

    GS> require 'etc'

    Ah! I don't know how I would have found that, though, given the name. :)

    Okay, so enumerating users is easy enough.

    require 'etc'
    class Users
    include Etc
    include Enumerable

    def each
    setpwent
    while pw = getpwent
    yield pw
    end
    endpwent
    end
    end

    Users.new.each { |u| puts u.name }

    Mark Guest

  9. #9

    Default Re: ruby way to enumerate users

    On Mon, 2 Feb 2004 07:54:50 +0900, Mark J. Reed wrote: 

    Simpler:

    require 'etc'
    class Users
    include Etc
    include Enumerable
    alias :each :passwd
    public :each
    end

    Users.new.each { |u| puts u.name }


    Eric Guest

  10. #10

    Default Re: ruby way to enumerate users

    MJR> require 'etc'
    MJR> class Users
    MJR> include Etc
    MJR> include Enumerable
    MJR> def each
    MJR> setpwent
    MJR> while pw = getpwent
    MJR> yield pw
    MJR> end
    MJR> endpwent
    MJR> end
    MJR> end
    MJR> Users.new.each { |u| puts u.name }

    ES> Simpler:
    ES>
    ES> require 'etc'
    ES> class Users
    ES> include Etc
    ES> include Enumerable
    ES> alias :each :passwd
    ES> public :each
    ES> end

    Simpler, but not equivalent. That version starts wherever the last
    call to getpwent passwd left off, instead of starting over at the
    first entry.

    -Mark
    Mark Guest

  11. #11

    Default Re: ruby way to enumerate users

    Eric Sunshine <com> wrote in message news:<com>... 
    >
    > Simpler:
    >
    > require 'etc'
    > class Users
    > include Etc
    > include Enumerable
    > alias :each :passwd
    > public :each
    > end
    >
    > Users.new.each { |u| puts u.name }[/ref]

    Apparently my earlier message got lost. There is no need to wrap this
    with the etc module.

    require "etc"
    Etc.passwd{ |s|
    p s.name
    p s.dir
    }

    This is doented in the Nutshell book and at
    http://www.rubygarden.org/ruby?ProgrammingRubyTwo/Etc

    Regards,

    Dan
    Daniel Guest

  12. #12

    Default Re: ruby way to enumerate users

    On Sun, Feb 01, 2004 at 07:33:52PM -0800, Daniel Berger wrote: 

    And when you pass a block it automatically resets to the first user,
    too. Cool. Thanks!

    -Mark


    Mark Guest

  13. #13

    Default Re: ruby way to enumerate users

    On 0202, Daniel Berger wrote: 

    BTW how can I read this book *offline*?

    Gergo

    --
    +-[ Kontra, Gergely<hu> PhD student Room IB113 ]---------+
    | http://www.mcl.hu/~kgergely "Olyan langesz vagyok, hogy |
    | Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom" |
    +-- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+


    KONTRA Guest

  14. #14

    Default Re: ruby way to enumerate users

    Something like Httrack will do the trick.

    http://www.theopenidea.org/tikiwiki/tiki-index.php?page=HTTrack


    Cheers

    Rove Monteux


    KONTRA Gergely wrote:
     
    >
    >BTW how can I read this book *offline*?
    >
    >Gergo
    >
    >
    >[/ref]

    --
    Rove Monteux
    Systems Administrator

    com




    Rove Guest

Similar Threads

  1. Replies: 0
    Last Post: November 1st, 05:21 PM
  2. Replies: 1
    Last Post: October 29th, 07:52 PM
  3. patch to the users who use BLOB of ruby-oci8
    By KUBO Takehiro in forum Ruby
    Replies: 0
    Last Post: September 18th, 03:13 PM
  4. Enumerate Methods
    By 台灣微軟技術處支援部 in forum ASP Components
    Replies: 0
    Last Post: August 21st, 02:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139