linux-shell-sessions

Parses utmp logs and retrieves the list of shell sessions currently logged into Linux. You can check the user, terminal, connected host, remote IP address, idle time, CPU time used, and running command line for each session.

Command properties

ItemDescription
Command typeDriver query
Required permissionAdministrator
License usageLicensed command
Parallel executionNot supported
Distributed executionRuns on Data Node (mapper)

Syntax

linux-shell-sessions

Output fields

FieldTypeDescription
userstringName of the logged-in user
ttystringTerminal device name
hoststringConnected host name
src_ipipaddrRemote connection IP address
idle_timelongIdle time (seconds)
jcpudoubleCPU time used by all processes running on the terminal (seconds)
pcpudoubleCPU time used by the current foreground process (seconds)
cmd_linestringCurrently running command line

Error codes

Parse errors
Error codeMessageDescription
95040no-read-permissionOccurs when run without administrator privilege
Runtime errors

N/A

Description

The linux-shell-sessions command parses the utmp file (the first readable among /var/log/utmp, /run/utmp, and /var/run/utmp) to retrieve information about currently logged-in shell sessions. It returns information similar to the Linux w command.

For each session, it extracts the username, terminal device, host, and remote IP address recorded in utmp. The idle time is calculated based on the last modification time of the terminal device file. CPU time (utime + stime) for the session process and its child processes is summed from the /proc filesystem and assigned to the jcpu and pcpu fields. The cmdline of the deepest child process is assigned to the cmd_line field.

Examples

  1. Retrieve current login sessions

    linux-shell-sessions
    

    Retrieves information about all shell sessions currently logged into the Linux system.

  2. Filter sessions for a specific user

    linux-shell-sessions
    | search user == "root"
    

    Filters only root user shell sessions.

  3. Sort by idle time

    linux-shell-sessions
    | sort -idle_time
    

    Retrieves sessions sorted from longest idle time to shortest.