Tag Archives: Bash

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.

#!/bin/bash
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>"
else
    echo "<result>$result</result>"
fi