Bash public

Logged-in Users

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/ZZ6VQR574YF5 | bash

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.467

At a glance

Script metadata

Slug
ZZ6VQR574YF5
Fetches
3
Size
1372 B · 62 lines
Expires
never
Last fetch
2026-09-07 02:17:50.794
Created
2026-09-07 00:36:00.569
Description
who/w snapshot of interactive sessions

Readable before runnable

Preview

#!/usr/bin/env bash
# Logged-in users
# Read-only: who and w session tables. Does not write utmp or force logouts.
# Exit 0 if sessions are listed, 1 if none, 2 if who/w are missing.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
note() { printf '%s\n' "$*"; }
bump() {
  case $1 in
    crit) status=2 ;;
    warn) [ "$status" -lt 1 ] && status=1 ;;
  esac
}

note "=== Logged-in users ==="
note "Host:     $(hostname 2>/dev/null || printf unknown)"
note ""

if command -v who >/dev/null 2>&1; then
  note "who:"
  who_out=$(who 2>/dev/null || true)
  if [ -z "${who_out}" ]; then
    note "  (no sessions)"
    bump warn
  else
    printf '%s\n' "$who_out" | while IFS= read -r row; do
      note "  ${row}"
    done
    n=$(printf '%s\n' "$who_out" | awk 'NF {n++} END {print n+0}')
    note "Sessions: ${n}"
    if [ "$n" -ge 20 ]; then
      note "          WARNING: unusually many login sessions"
      bump warn
    fi
  fi
else
  note "who:      not found"
  bump warn
fi
note ""

if command -v w >/dev/null 2>&1; then
  note "w:"
  w 2>/dev/null | while IFS= read -r row; do
    note "  ${row}"
  done
elif ! command -v who >/dev/null 2>&1; then
  note "w:        not found"
  bump crit
fi
note ""

case $status in
  0) note "Result: HEALTHY" ;;
  1) note "Result: WARNING" ;;
  *) note "Result: CRITICAL" ;;
esac
exit "$status"

Raw endpointhttps://runny.sh/r/ZZ6VQR574YF5

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision