How to tell how much your macs are actually being used in a large or enterprise environment.

If you have a lot of macs in your environment then you might have wondered how much they are actually being utilized. This is especially interesting if you have thousands of macs in a corporate or educational environment. For example if you have thousands of student macbooks in classrooms you could determine which classes or grade levels use them the most. You could do the same with teacher macbooks to see which teachers were using their machines the most.

 
ac | awk '{ print $2 }'

If you have multiple users on one mac such as if it were being used as a shared classroom computer, you could expand on the above code. The code below gets the total logged in time of all users and sorts them in descending order. The $most variable outputs the username who was logged in the most and the total hours that they have been logged in.

#!/bin/bash
 
## If you just type 'dscl /Local/Default -list /Users' you will get a lot of user accounts
## that start with _. Adding 'uid | awk '$2 >= 499 { print $1; }'' weeds out those users.
username=$(dscl /Local/Default -list /Users uid | awk '$2 >= 499 { print $1; }' | sort -n)
 
for user in ${username[@]}
do
 
acuser=$(echo "$user" & ac $user )
echo $acuser >> /path/to/testusers.txt
 
done
 
most=$(sort -nr -t' ' -k3 /path/to/testusers.txt | awk 'NR==1{print $1, $3}')
echo $most
rm -rf /path/to/testusers.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

*