Created
February 28, 2016 08:41
-
-
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.
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
#!/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