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
| Item | Description |
|---|---|
| Command type | Driver query |
| Required permission | Administrator |
| License usage | Licensed command |
| Parallel execution | Not supported |
| Distributed execution | Runs on Data Node (mapper) |
Syntax
Output fields
| Field | Type | Description |
|---|---|---|
user | string | Name of the logged-in user |
tty | string | Terminal device name |
host | string | Connected host name |
src_ip | ipaddr | Remote connection IP address |
idle_time | long | Idle time (seconds) |
jcpu | double | CPU time used by all processes running on the terminal (seconds) |
pcpu | double | CPU time used by the current foreground process (seconds) |
cmd_line | string | Currently running command line |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
95040 | no-read-permission | Occurs 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
-
Retrieve current login sessions
linux-shell-sessionsRetrieves information about all shell sessions currently logged into the Linux system.
-
Filter sessions for a specific user
linux-shell-sessions | search user == "root"Filters only root user shell sessions.
-
Sort by idle time
linux-shell-sessions | sort -idle_timeRetrieves sessions sorted from longest idle time to shortest.