Home Brew and Collect Application Usage Information
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
04-27-2017
06:19 AM
- last edited
a month ago
by
kh-richa_mig
Hello all
Apologies if this has already been asked and I have missed it, but has anyone got away of collecting the applications installed by home brew?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 06:37 AM
@Craig.Whittaker Does the command brew list
return the info you're looking for? If so, you can write an Extension Attribute to collect that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 06:42 AM
@StoneMagnet hey it does, but wanted to set up a smart group to filter on home brew installed machines only having this ran on them :/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 06:53 AM
@Craig.Whittaker EAs run on all machines, and aren't scoped. You could have the EA check for the existence of the file /usr/local/bin/brew
to determine if brew is installed on the machine, and either return Not Installed or the list of installed brew tools.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 06:57 AM
thanks @StoneMagnet
don't happen to have an example EA doing even something similar I can pick apart?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 07:04 AM
@Craig.Whittaker This is untested, but should do what you want:
#!/bin/bash
brewtools="Not Installed"
if [ -e /usr/local/bin/brew ]
then
brewtools=$(/usr/local/bin/brew list)
fi
echo "<result>$brewtools</result>"
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-27-2017 07:27 AM
@StoneMagnet great will give it a go
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 03-21-2018 02:30 PM
So i found this while looking for other information, About a year later from original post.. so i am turning this into a zombie post i guess..
jamf runs alot of what it does from an elevated state. Brew errors out if run as root. so the above may not work for people. and since I had to make an EA and there was a post needing an EA. i figured i would share in the serendipitous nature of finding this
This only pulls brew installs for logged in users, which means the scope can change based on inventory checkin, and active user. but if you are primarily on a One to One deployment, that shouldn't be an issue.
If you need to get brew installs for all users you could possibly loop through the results of dscl . list or something. but the output of that will be fun to format in a away that is user readable in jamf..
#!/bin/bash
###########################################
set -euo pipefail
IFS=$'
'
## Variables #################
loggedInUser=$(stat -f %Su /dev/console)
brewArray=()
## Work Area ####################
if [[ -d /Users/"${loggedInUser}"/brew ]]; then
while read -r brewApp; do
name=$(basename "$brewApp")
brewArray+=("${name}")
done < <(ls /Users/"${loggedInUser}"/brew/Cellar/)
echo "<result>$(printf '%s
' "${brewArray[@]}")</result>"
else
echo "<result>brew not installed</result>"
fi
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-05-2020 09:41 AM
Do dis:
in extension attrib:
- string
- extension attrib
- script
!/bin/sh
file="/Library/Caches/Homebrew"
if [ -d "$file" ]
then
echo "<result>"yes"</result>"
else
echo "<result>"No"</result>"
fi
or better yet:
!/bin/sh
file="/usr/local/bin/brew"
can also do cask in same way - /usr/local/bin/cask
if [ -f "$file" ]
then
echo "<result>"yes"</result>"
else
echo "<result>"no Present"</result>"
fi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 02-11-2021 11:47 AM
Adding to the zombie....
the if needs to be -x (executable) not -d (directory)
Also for M1/ARM machines: /opt/homebrew and it needs a -d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 10-19-2021 01:35 PM
so to add on to this question what if you wanted to track what brew apps are installed, inside jamf, and possibly usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 08-22-2024 10:59 PM
here's my version...
#!/bin/sh
brewDir=$(/usr/bin/find /opt /usr/local -d -maxdepth 1 -iname "homebrew" 2>/dev/null)
if [ "${brewDir}" ]; then
brewBin="${brewDir}/bin/brew"
brewOwner=$(id -nu "$(stat -f %u "${brewBin}")")
brewVers=$(sudo -u "${brewOwner}" "${brewBin}" config | grep HOMEBREW_VERSION | awk '{print $2}')
else
brewVers="Not Installed"
fi
printf %s "<result>${brewVers}</result>"
exit 0
