Created
February 13, 2024 01:20
-
-
Save hotta/b820b61449be29bde5b9e9791811608f to your computer and use it in GitHub Desktop.
display last login date for each users
This file contains hidden or 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 | |
# | |
# display last login date for each users | |
# | |
for user in vagrant dirsrv dummy ; do | |
if ! id $user >& /dev/null ; then | |
echo -e "$user\tno such user" | |
continue | |
fi | |
LINE="$(LANG=C lastlog -u $user | tail -1)" | |
# shellcheck disable=SC2086 # quoting will not set positional arguments | |
set ${LINE} | |
if [[ "$LINE" =~ Never ]] ; then | |
echo -e "${1}\tnever" | |
else | |
timestamp="${4} ${5} ${6} ${7} ${8} ${9}" | |
echo -e "${1}\t$(date --date="$timestamp" '+%Y/%m/%d')" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment