Posted on 02-09-2017 12:52 PM
One of our policies is that users log out of their machines at the end of every day they are here. We have a great amount of users who not do this. They log in on Monday, put the computer to sleep at the end of the day and wake it up in the morning. We have policy that restarts the machines every saturday morning, which forces users to log back in monday morning. By not logging out, they aren't getting important updates and are having continuous connectivity issues with our network drives.
My question is how can I make a smart group that pulls in machines of users who haven't logged out after so many days / hours. you would think that because casper records logouts this would be an option, but I don't see how... Please help :)
Posted on 02-09-2017 02:33 PM
You can get the last login time in epoch and convert it to the date format for Extension Attributes
#!/bin/bash
grabConsoleUserAndHome(){
currentUser=$(stat -f %Su "/dev/console")
homeFolder=$(dscl . read "/Users/$currentUser" NFSHomeDirectory | cut -d: -f 2 | sed 's/^ *//'| tr -d '
')
case "$homeFolder" in
* * )
homeFolder=$(printf %q "$homeFolder")
;;
*)
;;
esac
}
grabConsoleUserAndHome
lastLoginEpoch=$(syslog -F raw -k Facility com.apple.system.lastlog | grep -v tty | grep "$currentUser" | tail -n1 | awk '{print $4}' | tr -d ']')
lastLoginFormatted=$(date -j -f "%s" "$lastLoginEpoch" "+%Y-%m-%d %H:%M:%S")
echo "<result>"$lastLoginFormatted"</result>"
exit