Posted on 02-28-2012 09:49 PM
We slapped together a crude Extension Attribute to gather Outlook 2011 Identities folder sizes.
We know this can be shorter and "smarter". Any advice from the scripting uber-gurus? :)
#!/bin/bash
echo "<result>"
UserList=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for u in $UserList ;
do results=`du -sh /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/* | grep -v "[Back" | grep -v ".plist"`
echo $u $results
done
echo "</result>"
exit 0
Solved! Go to Solution.
Posted on 03-02-2012 03:42 PM
If you don't want false responses, how about
du -sh /Users/*/Documents/Microsoft User Data/Office 2008 Identities/*
grep -v "[Back"
should be:
grep -v "[Back"
grep -v ".plist"
should be
grep -v ".plist"
as the dot acts as a wild card.
If you want to remove admins, quick crude method:
#!/bin/bash
groupAdmin=`dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'`
du -sh /Users/*/Documents/Microsoft User Data/Office 2008 Identities/* | egrep -v ".plist|\[Back|/Users/$groupAdmin"
Posted on 03-07-2012 10:11 AM
Should do the tric:
#!/bin/bash
echo "<result>"
groupAdmin=dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'
UserList=dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'
for u in $UserList ;
do
if [ -d /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/ ]; then
results=du -sh /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/* | grep -v "[Back" | grep -v ".plist" | awk '{print $1}'
else continue
fi
echo "$u - $results"
done
echo "</result>"
exit 0
Using $u instead of a wildcard for the user prevents quote non-expansion silliness. the | awk '{print $1}' at the end of the resultys= command cuts off the file path to ~/Documents/bladdy blah and gives some nice clean output.
the if skips any user accounts with IDs above 500 that do not have a MS Identities folder.
PRINTS:
<result>
acaldwell - 702M
locadmin - 18M
diradmin - 18M
</result>
on my Mac.
Posted on 02-29-2012 06:17 AM
add-in request for the uber-guru's: a result of not installed or something. OHH and maybe a way to exempt an id, since our local admin account is being populated...
du: /Users/macadmin/Documents/Microsoft User Data/Office 2011 Identities/: No such file or directory grep: Unmatched [ or [^ macadmin du: /Users/momall0/Documents/Microsoft User Data/Office 2011 Identities/: No such file or directory grep: Unmatched [ or [^ momall0
Posted on 02-29-2012 11:14 AM
Hi John,
Yes, if the Extension Attribute can exclude any home directories that DON'T have Outlook 2011 Identities folders, that would be most awesome. :)
Don
Posted on 03-02-2012 02:34 PM
...bump :)
Posted on 03-02-2012 03:42 PM
If you don't want false responses, how about
du -sh /Users/*/Documents/Microsoft User Data/Office 2008 Identities/*
grep -v "[Back"
should be:
grep -v "[Back"
grep -v ".plist"
should be
grep -v ".plist"
as the dot acts as a wild card.
If you want to remove admins, quick crude method:
#!/bin/bash
groupAdmin=`dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'`
du -sh /Users/*/Documents/Microsoft User Data/Office 2008 Identities/* | egrep -v ".plist|\[Back|/Users/$groupAdmin"
Posted on 03-02-2012 06:42 PM
it's always been my experience that Casper will not recognize asterisks as wildcards and does not expand them in shell scripts. I'm using Casper 8.1... maybe it's just my me...
Posted on 03-03-2012 06:47 AM
Don't recall ever seeing that problem with asterisks. I get a successful EA from the above.
Sean
Posted on 03-03-2012 08:48 AM
Double quotes suppress the expansion of wildcard characters. If your path includes a wildcard then use backslashes to escape characters such as spaces instead of using quotes.
Posted on 03-05-2012 03:26 AM
The string I posted originally seemed to work. I thought the quotes escaped everything?
grep -v "[Back" | grep -v ".plist"
Is there a way to exclude any home directories that don't have a Microsoft User Data folder?
Thanks,
Don
Posted on 03-05-2012 03:47 PM
Anyone come up with a way to format the output in Casper more usefully?
ie - Only a username and size
eg.
David - 10g
John - 15g
Rob - 10g
Posted on 03-07-2012 07:39 AM
#!/bin/bash
echo "<result>"
groupAdmin=`dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'`
UserList=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for u in $UserList ;
do results=du -sh /Users/*/Documents/Microsoft User Data/Office 2008 Identities/* | grep -v "[Back" | grep -v ".plist"
# |/Users/$groupAdmin"
echo $u $results
done
echo "</result>"
exit 0
This outputs:
<result>
/Users/jwojda/Documents/outlook.sh: line 7: -sh: command not found
grep: brackets ([ ]) not balanced
jwojda
/Users/jwojda/Documents/outlook.sh: line 7: -sh: command not found
grep: brackets ([ ]) not balanced
macadmin
/Users/jwojda/Documents/outlook.sh: line 7: -sh: command not found
grep: brackets ([ ]) not balanced
macports
</result>
Posted on 03-07-2012 10:11 AM
Should do the tric:
#!/bin/bash
echo "<result>"
groupAdmin=dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'
UserList=dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'
for u in $UserList ;
do
if [ -d /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/ ]; then
results=du -sh /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/* | grep -v "[Back" | grep -v ".plist" | awk '{print $1}'
else continue
fi
echo "$u - $results"
done
echo "</result>"
exit 0
Using $u instead of a wildcard for the user prevents quote non-expansion silliness. the | awk '{print $1}' at the end of the resultys= command cuts off the file path to ~/Documents/bladdy blah and gives some nice clean output.
the if skips any user accounts with IDs above 500 that do not have a MS Identities folder.
PRINTS:
<result>
acaldwell - 702M
locadmin - 18M
diradmin - 18M
</result>
on my Mac.
Posted on 03-07-2012 10:45 AM
BTW,
Doesn't the dscl. read method of finding group membership only find users who are solely members of that group? A better way to find admin users might be dseditgroup -o checkmembership -u $u admin....
Not sure what you'd want with this though as admin users can still have active MS Identity folders...
just my $0.02
Posted on 03-07-2012 01:44 PM
@sean...you were right:
grep -v "[Back"
should be:
grep -v "\[Back"
grep -v ".plist"
should be
grep -v ".plist"
So this is how we have the script set up. We need the entire path since users can/do change their Identity name...
For Outlook 2011 folder sizes:
#!/bin/bash
echo "<result>"
UserList=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for u in $UserList ;
do
if [ -d /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ ]; then
results=`du -sh /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ | grep -v "\[Back" | grep -v ".plist"`
else continue
fi
echo $u $results
done
echo "</result>"
exit 0
For Entourage 2008 database sizes:
#!/bin/bash
echo "<result>"
UserList=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for u in $UserList ;
do
if [ -d /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/ ]; then
results=`du -sh /Users/$u/Documents/Microsoft User Data/Office 2008 Identities/*/Database | grep -v "[Back" | grep -v ".plist"`
else continue
fi
echo $u $results
done
echo "</result>"
exit 0
So the only issue now is the lack of line return on the output. We have dozens of analysts handling many Mac refreshes, so the ability to quickly see everyone's Entourage database, or Outlook folder size, is important.
Don
Posted on 03-08-2012 04:19 PM
#!/bin/bash
echo "<result>"
UserList=`dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'`
for u in $UserList ;
do
if [ -d /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ ]; then
results=`du -sh /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ | grep -v "[Back" | grep -v ".plist" | awk '{print $1}'`
else continue
fi
echo $u $results
done
echo "</result>"
This is what worked for me that I got back:
abnath 2.3G
Posted on 03-08-2012 06:21 PM
@jhbush1973 What do you get if a user has multiple identities?
Posted on 03-09-2012 04:47 PM
abnath 2.3G abnath 2.3G
I don't need the the full path to the folder like others do. The window in the JSS scrolls if you need to see the full path.
Posted on 01-09-2013 12:00 PM
On a related note, below is what I threw together to check the sizes of any 2004/2008 Identities on a machine and make sure there would be enough room for those machines to go through an Identity upgrade when 2011 rolled out. Never put it in production but it was my take and would be just as easy to make it work with 2011 and be an Extension Attribute.
#!/bin/bash
#Gets all user home folders parsing out non-user folders. Need to check for others
userlist=`ls /Users | egrep -v "Users|You|Can|Ignore"`
echo -e "Found the following users: "$userlist"
"
#Get startup volume total and free space and clean up DF output
totalspace=`df -k / | grep -vE '^Filesystem' | awk '{print $2 }'`
freespace=`df -k / | grep -vE '^Filesystem' | awk '{print $4 }'`
#Calculate what 10% of total space is on the HDD.
buffer=`echo $totalspace .1 | awk '{ printf("%.0f
", $1*$2) }'`
#Initialize variables
machine_users="Failed Machine Users:"
alldbsize=0
echo "Startup volume free space is $freespace out of $totalspace"
echo -e "Recommended free space is $buffer
"
#Initialize Failed user list
failed_users="Failed Users:"
#Loops through all user folders
for x in $userlist
do
#Initialize variables.
dbpath=""
dbsize=0
version=""
#Check if 2008 and/or 2004 DB files exist
if [ -f /Users/$x/Documents/Microsoft User Data/Office 2008 Identities/Main Identity/Database ]
then
#Set version for display in result
version=2008
#Set path to DB file
dbpath=/Users/$x/Documents/Microsoft User Data/Office 2008 Identities/Main Identity/Database
echo "$x is using Entourage $version"
#echo -e "$dbpath
"
else
#Check if 2008 and 2004 DB files exist
if [ -f /Users/$x/Documents/Microsoft User Data/Office 2004 Identities/Main Identity/Database ]
then
#Set version for display in result
version=2004
#Set path to DB file
dbpath=/Users/$x/Documents/Microsoft User Data/Office 2004 Identities/Main Identity/Database
echo "$x is using Entourage $version"
else
echo -e "No Entourage databases found in default locations for $x
"
fi
fi
if [ -n "$dbpath" ]
then
#Check size of database file
dbsize=`du -k "$dbpath" | awk '{print $1}'`
echo "DB is $dbsize"
#dbsize="45147265"
#Check size of database file in human readable format
readabledbsize=`du -h "$dbpath" | awk '{print $1}'`
echo -e "The size of $x Entourage $version database is $readabledbsize
"
#Calculate sum total of all DB files found
alldbsize=$(($alldbsize+$dbsize))
echo "all db $alldbsize"
#Create list of failed users with their version and DB size
machine_users="$machine_users $x($version)($readabledbsize)"
fi
done #for
echo "Total size of all DB files: $alldbsize"
echo -e "Buffer space on hard drive: $buffer
"
#Create result for JSS extension attribute
if [ $(($alldbsize+$buffer)) -ge $freespace ]
then
echo "<result>$machine_users</result>"
else
echo -e "Enough space to upgrade"
echo "<result>Ready</result>"
fi
Posted on 06-20-2013 02:09 AM
I've been trying out all of the above but still haven't got it to work properly. Not entirely sure what I might be doing wrong.
When running this:
#!/bin/bash echo "<result>" UserList=dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'
for u in $UserList ; do if [ -d /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ ]; then results=du -sh /Users/$u/Documents/Microsoft User Data/Office 2011 Identities/ | grep -v "[Back" | grep -v ".plist" | awk '{print $1}'
else continue fi echo $u $results done echo "</result>" exit 0
The result is: <result>
</result>
Posted on 06-20-2013 02:34 AM
Am running this through ARD now and it works fine!
#!/bin/bash groupAdmin=dscl . read /Groups/admin GroupMembership | cut -d " " -f 2- | sed 's/ /|/Users//g'
UserList=dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }'
for u in $UserList ; do if [ -d /Users/$u/Documents/Microsoft användardata/Office 2011 Identities/Main Identity ]; then results=du -sh /Users/$u/Documents/Microsoft användardata/Office 2011 Identities/Main Identity/* | grep -v "[Back" | grep -v ".plist" | awk '{print $1}'
else continue fi echo "$u - $results" done exit 0
But how do I get it to display the information when running inventory with Casper? I've added the script as an extention attribute and made sure that it's set populated by script. Still doesn't show up.
Edit: Figured it out now by reading the manual for Casper.
When an extension attribute is populated by a script, the text between the <result></result> tag is stored in the JSS. For Mac OS X computers, scripts can be written in any language that has an interpreter installed
Edit2: Nope, can't get any reports or results when I run inventory on it in Casper. Any suggestions?
Posted on 06-20-2013 12:04 PM
@makander, are you sure you're script is doing this at the end?
echo "<result>$u - $results</result>"
Note the quotes surrounding the tags and the text in between.
Also, if you only recently updated the Extension Attribute script, you need to make sure at least some of your Macs report in with new inventory. The data only gets collected during a full recon, not something like a check in., so I would force an inventory update against a Mac you know has an Office Identity folder and check again in the Inventory section of your JSS to see what shows up.
Posted on 06-24-2013 02:27 AM
@mm2270, I edited the script and made sure
echo "<result>$u - $results</result>"was there and ran recon on my machine. Still, can't get it to work properly as an attribute extention.