Posted on 07-30-2021 08:26 AM
My company uses a cloud file service called Egnyte. We deploy it for our clients as well. One of the functions of Egnyte is that it will sync a user's Desktop and/or Documents folder with the user's private folder in Egnyte. This is very useful if we need to give the user a temporary Mac while theirs is being repaired. All we need to do is sign in their Egnyte account, and all of the files that they're hoarding on the Desktop will appear within the amount of time it takes for the files to sync over from Egnyte. I am just now learning how to create extension attributes, but this particular scenario has so far eluded me. The first thing I do is find out who the current logged in user is:
currentuser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
echo $currentuser
Next, I tried entering: size=du -h /Users/$currentuser/Desktop
echo $size
That command is meant output the size of the Desktop folder for the current logged in user. If I type:
du -h /Users/$currentuser/Desktop/
It outputs this: 418M /Users/howie/Desktop/
If I type:
echo $size
It outputs this which is useless:
du -h Desktop
The script will error out stating that "-h" command not found. There are other errors that come up. I think I'm simply entering these commands with the wrong syntax. Maybe I need quotes and/or brackets. Because I can't get the output to come out correctly without errors, I can't even move on to the <result>XXX</result> command and wrap this up. This seemed so simple when I thought of it 🤔
Help please!
Solved! Go to Solution.
Posted on 07-30-2021 10:04 AM
This will do that:
#!/bin/bash
#Who is the current logged in user?
currentuser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#Size of the user's Desktop folder
size=$(du -h /Users/$currentuser/Desktop)
folderSize=$(echo $size | awk '{print $1}')
echo "<result>$folderSize</result>"
Posted on 07-30-2021 09:26 AM
Maybe try something like whats in here:
Extension Attribute for Document Folder Size - Jamf Nation Community - 65326
but change the folder to the desktop folder if thats what your after
Posted on 07-30-2021 09:32 AM
Thanks. I think I saw that post yesterday. I didn't try the idea posted, but I love having more ideas to try. My post that I made just when you replied seems to be the solution. I just went through the whole scripting series in the Jamf training catalog and I thought maybe a for loop might provide the solution. It did 😊
Posted on 07-30-2021 09:27 AM
I may have figured this out. Here's my extension attribute:
Posted on 07-30-2021 09:51 AM
If you are looking to get the full string "28K /Users/howie/Desktop" as the value in the EA, I would set the Data type to string and use this:
#!/bin/bash
#Who is the current logged in user?
currentuser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#Size of the user's Desktop folder
size=$(du -h /Users/$currentuser/Desktop)
echo "<result>$size</result>"
Posted on 07-30-2021 10:00 AM
Actually, what I wanted was just the size of the Desktop folder. I'm trying to figure out how to avoid having the extra results output. Fortunately, what is being displayed in the machine record is only the size of the Desktop folder. I appreciate any help I can get.
Posted on 07-30-2021 10:04 AM
This will do that:
#!/bin/bash
#Who is the current logged in user?
currentuser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#Size of the user's Desktop folder
size=$(du -h /Users/$currentuser/Desktop)
folderSize=$(echo $size | awk '{print $1}')
echo "<result>$folderSize</result>"
Posted on 07-30-2021 12:10 PM
Your script is way better than mine! I kept using the "du -h" command and I would get errors. I knew it had to be that I was using it incorrectly or using the wrong syntax. I decided to use a for loop simply because I saw a for loop being used in one of the scripting series videos. They showed how to run a command at the beginning of the for loop, and I thought it might solve my problem. It did, but you have done a better job. Thanks for your help! I have already thought of other ideas on how to use what you have posted here.
07-30-2021 12:16 PM - edited 07-30-2021 12:18 PM
I know this is some what related but here is an extension attribute to get the files and folder in the home users directory. I hope this is helpful
#!/bin/zsh
# Gets currently logged in user
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name 😕 && ! /loginwindow/ { print $3 }' )
the 😕 = : / without the space
# Gets the files
DSKTP=$( find /Users/$loggedInUser/Desktop -type f | sed 's/.DS_Store//g ' | sed 's/.localized//g ' | Sort )
DOCS=$( find /Users/$loggedInUser/Documents -type f | sed 's/.DS_Store//g ' | sed 's/.localized//g ' | Sort )
DWNLD=$( find /Users/$loggedInUser/Downloads -type f | sed 's/.DS_Store//g ' | sed 's/.localized//g ' | Sort )
# Adds the output into Jamf
OUTPUT="$DSKTP $DWNLD $DOCS"
/usr/bin/printf "<result>$OUTPUT</result>"
Posted on 07-30-2021 12:19 PM
Thanks! I like this. I have been trying (unsuccessfully) for years to get users to stop storing everything on the desktop. It can and often does cause problems as does hoarding downloads. I recently created a configuration profile that forces on the setting to empty trash after 30 days.
Posted on 07-30-2021 12:21 PM
can you share the empty trash profile. I created one in policies but does not seem to work properly
07-30-2021 12:31 PM - edited 07-30-2021 12:37 PM
Here's a screenshot of the Applications & Custom Settings payload in the profile.
Here's the plist text.
plutil -convert xml1 PlistName.plist
For some reason, some text is being replaced after I save the post! 😱 I guess it's because there's a cuss word in the text. The screenshot has the correct text though.
Posted on 07-30-2021 01:48 PM
Yes, it looks like "OldTrashItems" gave our filter a run for its money. Thanks for posting the screenshot. Here it is again in case someone misses it above.
Posted on 07-30-2021 01:49 PM
There's another post on the thread that received an emoji to replace some text. Thanks for working on this.
Posted on 08-02-2021 10:18 AM
I created a feature request about this filter. It either needs to be more intelligent, or removed altogether. We post scripts in Jamf Nation a lot, and we don't need our text being replaced.
08-02-2021 10:21 AM - edited 08-02-2021 10:22 AM
If you click on the ... in the post window, you can then click on </> and it will allow you to input code.
it will show up like this: 😕
well that is interesting it even did it inside my code window....thats a first!!!
Posted on 08-02-2021 10:24 AM
That's annoying. The new Jamf Nation looks good but this filter is just too obnoxious. This needs to be fixed. Now.