Skip to main content
Question

Home Brew and Collect Application Usage Information

  • April 27, 2017
  • 11 replies
  • 76 views

Forum|alt.badge.img+3

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?

11 replies

Forum|alt.badge.img+8
  • Contributor
  • April 27, 2017

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


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 27, 2017

@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 :/


Forum|alt.badge.img+8
  • Contributor
  • April 27, 2017

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


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 27, 2017

thanks @StoneMagnet

don't happen to have an example EA doing even something similar I can pick apart?


Forum|alt.badge.img+8
  • Contributor
  • April 27, 2017

@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

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • April 27, 2017

@StoneMagnet great will give it a go

thanks


exno
Forum|alt.badge.img+14
  • Contributor
  • March 21, 2018

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

Forum|alt.badge.img
  • New Contributor
  • November 5, 2020
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


Forum|alt.badge.img+5
  • Contributor
  • February 11, 2021

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


Forum|alt.badge.img+3
  • New Contributor
  • October 19, 2021

so to add on to this question what if you wanted to track what brew apps are installed, inside jamf, and possibly usage.


Forum|alt.badge.img+8

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