@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
You could then create a smart group that checks if the EA is not "Has Work Folder"
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
@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
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
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
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...
Thanks! @aporlebeke
I gave you credit in the script. ;)
@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?
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.
@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?
@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.
@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!
@skeenan07 thank you so much for that cheat sheet and I plan to dive more into all of this.
You may also find this helpful: https://google.github.io/styleguide/shellguide.html