Skip to main content
Solved

Looking for the presence of a specific folder on a machine

  • July 21, 2016
  • 3 replies
  • 32 views

Forum|alt.badge.img+3

I am trying to search all my machines for the presence of a local Google Drive folder. Borrowing from a script I have found in another thread I have set up an extension attribute with a script, but it is not recognizing the folder. Assuming the issue lies with the variable in the path to folder, but unsure how to rectify. (I am open to other options if extension attribute is not the way to go. New to the Casper Suite and still learning my way through) Thanks!

!/bin/bash

if [ -d "/Users/${loggedInUser}/Google Drive" ]; then
echo "<result>Has Work Folder</result>"
else
echo "<result>Does Not Have Work Folder</result>"
fi

exit

Best answer by mpermann

@jcolucciello where are you specifying the the value for loggedInUser? I've seen people use the following for that:

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

3 replies

mpermann
Forum|alt.badge.img+22
  • Valued Contributor
  • Answer
  • July 21, 2016

@jcolucciello where are you specifying the the value for loggedInUser? I've seen people use the following for that:

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • July 21, 2016

@mpermann Adding that looks like it did the trick. Thanks so much for the quick and helpful response!


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • July 21, 2016

Yes, ${loggedInUser} is not being defined anywhere in your script. So its using a path of "/Users//Google Drive" since the username is blank, so of course its not finding it. You can add a variable for that like @mpermann shows above. There are several other options to grab the logged in user. Another one I use these days is:

stat -f%Su /dev/console

And there's a python Apple approved way out there as well if you search around on here.