Skip to main content
Question

EA help - script


Forum|alt.badge.img+8

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

sharriston
Forum|alt.badge.img+9
  • Valued Contributor
  • 146 replies
  • February 6, 2019
#!/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.


Forum|alt.badge.img+11
  • Valued Contributor
  • 142 replies
  • February 6, 2019
#!/bin/bash

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

Forum|alt.badge.img+8
  • Author
  • Contributor
  • 142 replies
  • February 20, 2019

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
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • February 20, 2019

@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'


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 142 replies
  • February 20, 2019

Thank you :)


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 142 replies
  • February 20, 2019

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
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • February 20, 2019

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


Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • February 20, 2019

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

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings