Looking for the presence of a specific folder on a machine

jcolucciello
New Contributor

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

1 ACCEPTED SOLUTION

mpermann
Valued Contributor II

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

View solution in original post

3 REPLIES 3

mpermann
Valued Contributor II

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

jcolucciello
New Contributor

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

mm2270
Legendary Contributor III

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.