Tag Archives: Mac

JSS Bash Script to Determine Last Logged On User

Below is a small Bash script I wrote to determine the last logged on user on Mac machines and log it to the JSS server via an extension attribute.

result=`last | grep -v -E '(reboot|shutdown|root)' | grep 'console' -m 1 | awk '{print $1}'`
if [ -z $result ]; then
   echo "<result>(No recent logons)</result>"
    echo "<result>$result</result>"