EA help - script

Captainamerica
Contributor II

I am beginner in scripting, but managed to find the following and it is working

#!/bin/bash

if [ -d /Library/Updates/041-31306 ]; then
echo "<result>TRUE</result>"
else
echo "<result>FALSE</result>"

exit

Is there a way to build in another path into the same EA - So both Library1 and library 2 must exist (TRUE/FALSE) - or must I create 2 seperate EA for each?

8 REPLIES 8

sharriston
Contributor III
#!/bin/sh

if [[ -e /Library/Updates/041-31306 && -e /other/file/path ]]; then
echo "<result>TRUE</result>"
else
echo "<result>FALSE</result>"

fi

I tested on my machine with two dummy files. If both exist it will echo true if one is missing it will echo false. Hope this helps.

ShaunRMiller83
Contributor III
#!/bin/bash

if [[ -d  "/path/to/folder/subfolder1" && -d  "/path/to/folder/subfolder2" ]]; then
    echo "<result>TRUE</result>"
else
    echo "<result>FALSE</result>"
fi

Captainamerica
Contributor II

Sorry - just found out that I initially wrote this topic the wrong way.

I want that if Folder1 OR folder2 exist it must be TRUE. I wrote that both folders must exist in the opening post

mm2270
Legendary Contributor III

@Captainamerica In either example above, change && to || and it should give you the results you're looking for.
The && means 'and' (obviously), and || means 'or'

Captainamerica
Contributor II

Thank you :)

Captainamerica
Contributor II

Maybe a bit off topic. But on the mac I run the above script but the extension attribute still show "false" even the folder is there. If I run the same scipt in coderunner on the mac, it shows true. So code is working
I have of course run a recon and inventory is also updated according to Jamf

Has anyone expierenced that before ?

mm2270
Legendary Contributor III

What are the paths to the folders exactly? Also, can you post the exact script code you're using?

ryan_ball
Valued Contributor

Try this:

#!/bin/bash

if [[ -d  "/path/to/folder/subfolder1" ]] || [[ -d  "/path/to/folder/subfolder2" ]]; then
    echo "<result>TRUE</result>"
else
    echo "<result>FALSE</result>"
fi