
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 10:55 AM
Hello Everyone,
Does anyone know of a way to spec out a smart group that looks for the existence of a folder? For instance, if a directory such as "work" exists in /Users/Shared I can find all of the computers where this folder exists in /Users/Shared/work.
I cannot find any criteria that seems to match up to this.
Thoughts?
Thank you as always!!
Mick
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:04 AM
@mconners you'd have to create an extension attribute. Something I wrote real quick that would do what you want.
#!/bin/bash
if [ -d /path/to/directory ]; then
echo "<result>Has Work Folder</result>"
else
echo "<result>Does Not Have Work Folder</result>"
fi
exit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:23 AM
@mconners It's not difficult. Basic steps:
- JSS Settings
- Go to Computer Management
- Click Extension Attributes
- Click New
- Give the EA a name
- Give the EA a description
- Leave the Data Type as "String"
- Choose where you'd like the EA to be displayed in inventory
- Set the Input Type to Script
- Add your script to the section that appears.
- Save
- Update inventory on a laptop and verify the EA populates with the desired text.
- Create your smart group based on the EA criteria

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:04 AM
@mconners you'd have to create an extension attribute. Something I wrote real quick that would do what you want.
#!/bin/bash
if [ -d /path/to/directory ]; then
echo "<result>Has Work Folder</result>"
else
echo "<result>Does Not Have Work Folder</result>"
fi
exit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:07 AM
You could then create a smart group that checks if the EA is not "Has Work Folder"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:15 AM
Thank you @aporlebeke for such a quick response. I have never written or tried to make my own extension attribute. Is this a daunting undertaking? By what you gave me, it looks fairly straight forward.
Mick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:23 AM
@mconners It's not difficult. Basic steps:
- JSS Settings
- Go to Computer Management
- Click Extension Attributes
- Click New
- Give the EA a name
- Give the EA a description
- Leave the Data Type as "String"
- Choose where you'd like the EA to be displayed in inventory
- Set the Input Type to Script
- Add your script to the section that appears.
- Save
- Update inventory on a laptop and verify the EA populates with the desired text.
- Create your smart group based on the EA criteria

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:51 AM
Thank you again @aporlebeke, this worked just like envisioned. Now to put it all together with the other pieces I am fixing up.
Thanks again!!!
Mick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 11:58 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-22-2016 01:46 PM
Happy to help :) I'm a bit of a scripting newbie, so when I saw something I knew how to do I jumped on it :P

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 01-22-2018 08:26 AM
For posterity, I was looking for a way to detect the presence of an alias on the desktop. I used this to do so:
#!/bin/bash
if [ -e /path/to/file ]; then
echo "<result>Has Alias</result>"
else
echo "<result>Does Not Have Alias</result>"
fi
exit
This will work for regular files too.
The trick is getting the right user directory. We have all devices auto-login to an account, called "default" so it was easy for us. For people who actually log IN to their device, instead of using a default account, you need to add some logic to get the proper directory.
Of course, if your users are smart enough to log in, maybe they're smart enough to not need aliases on the desktop...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-04-2018 12:46 PM
Thanks! @aporlebeke I gave you credit in the script. ;)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-29-2021 06:56 PM
@apizz thank you for the solution to this!
Hate to bump this though but what if you wanted to find two directories at the same time in one EA? Good or bad to do?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-29-2021 07:03 PM
Not inherently bad. Like anything it depends on your use case. Grouping together can make it easier or harder to use as criteria as part of a smart group. Details around your use case would help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-29-2021 08:06 PM
@apizz Just shared below on another thread:
#!/bin/bash
if [ -d /Library/Application Support/CrowdStrike/Falcon ] && [ -d /Applications/Falcon.app/Contents/Resources ]; then
echo "<result>Installed</result>"
else
echo "<result>Not Installed</result>"
fi
But it came back on a known good machine with not installed. So I thought ok break each one down and whats odd is that
/Library/Application Support/CrowdStrike/Falcon
Doesn't work and I'm wondering if thats due to SIP protection? Even on its own it shows no folder is "installed" but I can get to it without issue within finder or see it in terminal. Any thoughts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-29-2021 08:56 PM
@daniel_ross so the reason you're getting a folder does not exist is because you're not including quotes to encapsulate your first folder path. A computer doesn't know that the space in the 'Application Support' folder is part of the path and not a second argument.
I'd definitely encourage you to look up bash scripting best practices, but in general I use quotes and variables wherever possible to make things easier on myself. So I would make the following tweaks to your EA:
#!/bin/bash
PATH1="/Library/Application Support/CrowdStrike/Falcon"
PATH2="/Applications/Falcon.app/Contents/Resources"
if [ -d "$PATH1" ] && [ -d "$PATH2" ]; then
RESULT="Installed"
else
RESULT="Not Installed"
fi
/bin/echo "<result>$RESULT</result>"
Of course, you could go further (I would) to add elif statements to isolate specifically which specific folder is missing or that both are missing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-30-2021 03:58 PM
@apizz thank you so much for the advice and helping out with that! I agree I need to dive more into bash scripting! Do you have any good pointers of where to start? I could really use it and love how this community helps and encourages one another!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-31-2021 10:38 AM
@daniel_ross I use this Bash Scripting Cheatsheet all the time.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-31-2021 06:34 PM
@skeenan07 thank you so much for that cheat sheet and I plan to dive more into all of this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-13-2021 03:12 PM
You may also find this helpful: https://google.github.io/styleguide/shellguide.html
