Created
August 25, 2021 18:33
-
-
Save jahkeup/8c89d9815ed7893a68f76f522544128a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
hash loginctl awk | |
log() { echo "[$(date --iso-8601=s)] $*" >&2; } | |
if ! loginctl show-session &>/dev/null; then | |
log "ERROR: no logind session found" | |
exit 1 | |
fi | |
{ | |
HEADER=("SESSION" "USERNAME" "XORG-DISPLAY") | |
(IFS=$'\t'; echo "${HEADER[*]}") | |
loginctl list-sessions | | |
awk -v OFS=$'\t' \ | |
'$4 ~ /seat[0-9]+/ { | |
display_cmd = "loginctl show-session --value -p Display "$1; | |
display_cmd | getline xorg_display; | |
print $1, $3, xorg_display; | |
close(display_cmd); | |
}' | |
} | | |
column -t | | |
{ | |
# print header to stderr | |
sed -u '1q' >/dev/stderr | |
# rest to stdout | |
cat | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment