Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
last login time
#!/bin/sh
# Marnin, RU ITS, version .1, 11-2014
# Source: http://superuser.com/questions/65375/user-login-log-on-mac-os-x
echo
echo "Check the last login time for an account"
echo
hostname=`HostName`
echo "Enter the NetID to check:"
read user
# entire log of login info
# /usr/bin/syslog -F raw -k Facility com.apple.system.lastlog | grep $user
# just the epoch time
lastlogin=`/usr/bin/syslog -F raw -k Facility com.apple.system.lastlog | grep $user | awk '{ print $4 }' | sed -e 's/]//g' | tail -1`
# The date is displayed as the epoch time. You can also convert to normal time with epochconverter.com
converttime=`date -r $lastlogin '+%m/%d/%Y:%H:%M:%S'`
echo
echo "Last login for $user on $hostname was $converttime"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.