Get a list of registered users

How to get a list of registered users in Linux with Ruby, without having to process the output wor who?

If the only way with Rubygem is fine, but if there is a way to do it without installing anything AND without using any external programs that would be really good.

+4
source share
2 answers

Since you noted your question “Linux”, I would go for something like:

who | cut -f2 -d " "
console
ttys000

Or inside irb:

$ irb
1.9.3p194 :001 > exec 'who | cut -f2 -d " "'
console
ttys000

see also: Other options for running a shell command .

, Etc:

$ irb
1.9.3p194 :001 > require 'etc'
 => true 
1.9.3p194 :002 > Etc.getlogin
 => "DudeRoot" 

- .c, , , github.

0

Rubygem , API utmp: rutmp

getutent .

, , w, , , Linux.

?

0

Source: https://habr.com/ru/post/1536261/


All Articles