Kanrisuru

who

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

Basic Usage

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

result = host.who
result.success?
true

result[0].user
'ubuntu'

result[0].ip.to_s
'172.16.30.1'

Parameters

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

Result

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

host.who
[
  [0] #<Struct:Kanrisuru::Core::System::UserLoggedIn:0x00000730
    command = "irb",
    idle = "3.00s",
    ip = #<IPAddr: IPv4:172.16.30.1/255.255.255.255>,
    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