Skip to content

Instantly share code, notes, and snippets.

@wbadart
Created February 28, 2016 08:41
Show Gist options
  • Save wbadart/88d919262eec964425d3 to your computer and use it in GitHub Desktop.
Save wbadart/88d919262eec964425d3 to your computer and use it in GitHub Desktop.
Curious to see who's logged on with you? Run this shell script to identify your fellow users.
#!/bin/bash
passwdPattern="(\w+ ){1,3}\w+"
finalCmds=false
while getopts u arg; do
case $arg in
u)
passwdPattern="^\w+.*(\w+ ){1,3}\w+"
finalCmds=true
;;
esac
done
names=$(users | xargs getent passwd | grep -Po "$passwdPattern" | sort | uniq)
if $finalCmds; then
echo "$names" | cut -d ':' -f 1,5 | awk -F':' '{printf "%10s: %-20s\n", $1, $2 }'
else
echo "$names"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment