Get information about users who are currently logged in with ruby.
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.who




Field Type Description
username string
Name of user to get login information about.


Returns an array of UserLoggedIn struct.

UserLoggedIn Fields

Field Type Description
user string The name of the currently logged in user.
tty string The name of the terminal the user is logging in from.
ip IPAddr The IP address of the terminal or host the user is logging in from.
login string The time the user logged in, in a 24-hour format.
idle string The time since the user last used the terminal; displays ?xdm? if the user is currently active.
jcpu string The total run time of all system processes attached to the user's terminal.
pcpu string Elapsed time for the user's current process.
command string The name of the user's current process.

Return Example

  [0] #<Struct:Kanrisuru::Core::System::UserLoggedIn:0x00000730
    command = "irb",
    idle = "3.00s",
    ip = #<IPAddr: IPv4:>,
    jcpu = 1.73,
    login = "19:17",
    pcpu = 1.47,
    tty = "pts/0",
    user = "ubuntu"

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES