Hi,
exists there a preferred ruby way to enumerate the
users names and directories?
especially on linux
Hi,
exists there a preferred ruby way to enumerate the
users names and directories?
especially on linux
“Robert K.” anon@nospam.de schrieb im Newsbeitrag
news:401d3b89$0$24652$9b4e6d93@newsread2.arcor-online.net…
Hi,
exists there a preferred ruby way to enumerate the
users names and directories?especially on linux
Maybe something like this
ruby -naF: -e ‘printf “%s\t%s\n”, $F[0], $F[5]’ /etc/passwd
robert
“Robert K.” anon@nospam.de schrieb im Newsbeitrag
news:401d3b89$0$24652$9b4e6d93@newsread2.arcor-online.net…
Hi,
exists there a preferred ruby way to enumerate the
users names and directories?especially on linux
Maybe something like this
ruby -naF: -e ‘printf “%s\t%s\n”, $F[0], $F[5]’ /etc/passwd
robert
Maybe something like this
ruby -naF: -e ‘printf “%s\t%s\n”, $F[0], $F[5]’ /etc/passwd
Is this allways applicable? For example in an NIS+ env
THX
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
On Sun, Feb 01, 2004 at 08:43:11PM +0100, Robert K. wrote:
Maybe something like this
ruby -naF: -e ‘printf “%s\t%s\n”, $F[0], $F[5]’ /etc/passwd
Is this always applicable? For example in an NIS+ env
- that’s why I’m asking.
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!
Others: Is this the case?
Do I have to or may I develope that module?
-Mark
require ‘etc’
(Should be in PickAxe, definitely in Nutshell.)
Gavin
On Monday, February 2, 2004, 8:14:50 AM, Mark wrote:
On Sun, Feb 01, 2004 at 08:43:11PM +0100, Robert K. wrote:
Maybe something like this
ruby -naF: -e ‘printf “%s\t%s\n”, $F[0], $F[5]’ /etc/passwd
Is this always applicable? For example in an NIS+ env
- that’s why I’m asking.
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!
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
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 }
Simpler:
require ‘etc’
class Users
include Etc
include Enumerable
alias :each :passwd
public :each
end
Users.new.each { |u| puts u.name }
On Mon, 2 Feb 2004 07:54:50 +0900, Mark J. Reed wrote:
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 }
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 }
Simpler:
require ‘etc’
class Users
include Etc
include Enumerable
alias :each :passwd
public :each
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
Eric Sunshine sunshine@sunshineco.com wrote in message news:200402012329.AA01538@sunshineco.com…
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 }Simpler:
require ‘etc’
class Users
include Etc
include Enumerable
alias :each :passwd
public :each
endUsers.new.each { |u| puts u.name }
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 documented in the Nutshell book and at
http://www.rubygarden.org/ruby?ProgrammingRubyTwo/Etc
Regards,
Dan
On Mon, 2 Feb 2004 07:54:50 +0900, Mark J. Reed wrote:
And when you pass a block it automatically resets to the first user,
too. Cool. Thanks!
-Mark
On Sun, Feb 01, 2004 at 07:33:52PM -0800, Daniel Berger wrote:
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
}
BTW how can I read this book offline?
Gergo
On 0202, Daniel Berger wrote:
This is documented in the Nutshell book and at
http://www.rubygarden.org/ruby?ProgrammingRubyTwo/Etc
–
±[ Kontra, Gergelykgergely@mcl.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 --+
Something like Httrack will do the trick.
http://www.theopenidea.org/tikiwiki/tiki-index.php?page=HTTrack
Cheers
Rove Monteux
KONTRA Gergely wrote:
On 0202, Daniel Berger wrote:
This is documented in the Nutshell book and at
http://www.rubygarden.org/ruby?ProgrammingRubyTwo/EtcBTW how can I read this book offline?
Gergo
–
Rove Monteux
Systems Administrator