Best methods to search for the existence of a file

bravestface
New Contributor

Good morning,

I am wondering if anyone has any tried and true method for searching for the existence of a file on a specified scope of machines? We are being asked to look for a specific file that would determine if a certain add-on pack is installed for Virtualbox. Any tried and true methods for running a process on a specific list of machines and determining if a file exists?

Thanks
D

 

6 REPLIES 6

karthikeyan_mac
Contributor III

You can try "Files and Process" payload of policies.

Screenshot 2022-11-08 at 7.00.46 PM.png

edamelio
New Contributor II

I would probably make an extension attribute and use the builtin "find" command to test for the presence of that file and then any other tests you would want to do. 

find Man Page - macOS - SS64.com

donmontalvo
Esteemed Contributor II

Have you tried an EA?

#!/bin/sh

if [ -f /path/to/file ]
then
	echo "<result>Exists</result>"
else
	echo "<result>DoesNotExist</result>"
fi
--
https://donmontalvo.com

@bravestface ditto what @donmontalvo  is saying, then create a smart group based on the criteria derived from the extension attribute.

_gsm
New Contributor III

I used the following with a Smart Group. If you're in higher ed, it's probably student machines.

 

#!/bin/bash

LicenseFilePath="/Applications/VirtualBox.app/Contents/MacOS/ExtensionPacks/Oracle_VM_VirtualBox_ Extension_Pack/ExtPack-license.html"

if [[ -e "${LicenseFilePath}" ]]; then
    EA_RESULT="Installed"
else
    EA_RESULT="Not installed"
fi

echo "<result>${EA_RESULT}</result>"

 

Thank you for all the great ideas. I'll reach back out if I have additional questions!

 

-D