Results 1 to 2 of 2
Hello. I'm looking for a script that can do two things: (1) determine the shortname of the user with the largest account in /Users and (2) look up their full/long ...
- 12-13-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 6
[SOLVED] How to find login user with the largest account
Hello. I'm looking for a script that can do two things: (1) determine the shortname of the user with the largest account in /Users and (2) look up their full/long name. I'm going to use this script to help identify who the user on a computer and while I know that's possible that a sometime-user may have a larger account than the normal-user on any given computer, the results of a script should be sufficient in most cases for my needs.
I'm not sure the best way to around this. I know that can use "du -m -d1 /Users" as root:
root on torchwood
[ ~ ]$ du -m -d1 /Users
157 /Users/admin
128 /Users/johndoe
70890 /Users/dancollins
21746 /Users/Shared
92920 /Users
I know that I can also use "dscacheutil -q user" to get a full list of all users on a system.
How can I get both the short and long name of the user with the largest account in the /Users folder?Last edited by da2357; 12-13-2010 at 04:25 PM. Reason: Make title clearer
- 12-14-2010 #2Just Joined!
- Join Date
- Nov 2010
- Posts
- 6
Courtesy of a fellow scripter on one of the Apple discussion lists, a solution has been found:
#!/bin/sh
#
# find_largest_account
# ver 1.00, 12.14.2010
#
max_usage=0
for user in $( dscl . -list Users )
do
eval [ -d ~$user ] || continue
usage=$( eval du -d0 ~$user | awk ' { print $1 } ' )
[ $usage -le $max_usage ] && continue
max_usage=$usage
hog=$user
done
echo $hog
dscacheutil -q user -a name $hog | grep ^gecos | cut -c8-
exit 0
Thanks to everyone for looking at my question.


