Skip to main content
Solved

Problem with extension attribute to find Outlook identity size


Forum|alt.badge.img+6

I have been working on an extension attribute to display the size of the Outlook identity on client macs. I have taken some cues from the posting here , and although that script works for me it generates a list of all users and the directory names. I would like to simply get the size of the folder for the currently logged in user, as I am not interested in the Outlook folder sizes for our local admin or shared accounts. Here's what I have so far:

#!/bin/bash

echo "<result>"

if test -e /Users/$USER/Documents/Microsoft User Data/Office 2011 Identities ; then
du -sh /Users/$USER/Documents/Microsoft User Data/Office 2011 Identities | cut -f1
else echo "Not Found"
fi
echo "</result>"
exit 0

When i run this script locally, it returns

591M

Which is what i want. However, in the JSS, it always returns "Not Found". Any ideas on what is wrong here? It is probably something small and obvious, as I am fairly new to scripting

Best answer by mm2270

Its most likely the use of $USER in your script that its getting tripped up on. EA scripts run as root, not as the logged in or current user, so when you use $USER its looking to get the size of a folder in the root account's home directory, which doesn't exist of course.

Try something like this-

#!/bin/sh

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

if [[ "$loggedInUser" != "root" ]] && [[ -e "/Users/${loggedInUser}/Documents/Microsoft User Data/Office 2011 Identities" ]]; then
    result=$(du -sh "/Users/${loggedInUser}/Documents/Microsoft User Data/Office 2011 Identities" | awk '{print $1}')
else
    result="N/A"
fi

echo "<result>$result</result>"
View original
Did this topic help you find an answer to your question?

5 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • March 25, 2015

Its most likely the use of $USER in your script that its getting tripped up on. EA scripts run as root, not as the logged in or current user, so when you use $USER its looking to get the size of a folder in the root account's home directory, which doesn't exist of course.

Try something like this-

#!/bin/sh

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

if [[ "$loggedInUser" != "root" ]] && [[ -e "/Users/${loggedInUser}/Documents/Microsoft User Data/Office 2011 Identities" ]]; then
    result=$(du -sh "/Users/${loggedInUser}/Documents/Microsoft User Data/Office 2011 Identities" | awk '{print $1}')
else
    result="N/A"
fi

echo "<result>$result</result>"

Forum|alt.badge.img+17
  • Valued Contributor
  • 231 replies
  • March 25, 2015

$USER would be root, assuming it is anything at all, when running an extension attribute. You'll need to iterate through user accounts to get results, and be prepared for multiple ones.

Completely untested, never run, freehand code:

#!/bin/sh
echo "<result>";
for i in `ls -d /Users/*`;
do
if test -e $i/Documents/Microsoft User Data/Office 2011 Identities ; then
echo -n "${i:7} - ";
du -sh $i/Documents/Microsoft User Data/Office 2011 Identities | cut -f1
fi; 
done
echo "</result>"

A note to others who may stumble upon this: Don't assume everybody has a home folder in /Users/. Query dscl to find homes.


Forum|alt.badge.img+6

Interesting, as $USER worked for a different script I made...

Anyway, that looks like it works for me. Thanks!


Forum|alt.badge.img+4
  • New Contributor
  • 6 replies
  • February 26, 2016

@mm2270 How would one modify the script to return the size of just the most recently modified identity inside of "/Users/${loggedInUser}/Documents/Microsoft User Data/Office 2011 Identities" ?


bpavlov
Forum|alt.badge.img+18
  • Esteemed Contributor
  • 1206 replies
  • February 26, 2016

you could possibly make use of:

ls -lt

which would sort a directory by last date modified. might need to use grep or awk to determine what line that is.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings