Skip to content

Instantly share code, notes, and snippets.

@hotta
Created February 13, 2024 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotta/b820b61449be29bde5b9e9791811608f to your computer and use it in GitHub Desktop.
Save hotta/b820b61449be29bde5b9e9791811608f to your computer and use it in GitHub Desktop.
display last login date for each users
#!/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