Skip to main content
Solved

Help With Extension Attribute

  • August 24, 2021
  • 5 replies
  • 46 views

Forum|alt.badge.img+4

Hello,

I need to setup a simple extension attribute to display the installed version of Python on our MacBooks. I'm using the following script input, but the display in machine inventory for the extension attribute remains blank. What am I missing? Here is the script:

#!/bin/sh PY=`python --version` echo "<result>$PY</result>" exit 0

That should do it, right?

Any help is appreciated!

Best answer by boberito

For whatever reason the python command doesn't output to stdout so you have to redirect it.

 

#!/bin/sh PY=$(python --version 2>&1) echo "<result>$PY</result>" exit 0

5 replies

boberito
Forum|alt.badge.img+22
  • Jamf Heroes
  • Answer
  • August 24, 2021

For whatever reason the python command doesn't output to stdout so you have to redirect it.

 

#!/bin/sh PY=$(python --version 2>&1) echo "<result>$PY</result>" exit 0

Forum|alt.badge.img+4
  • Author
  • Contributor
  • August 24, 2021

THANK YOU! That did it.


donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • August 25, 2021

If you need the version number for comparisons:

 

/usr/bin/python --version 2>&1 | awk '{ print $2 }'

 


For python 3 opensource:

 

/usr/local/bin/python3 --version | awk '{print $2}'

 

 

 

 

 

 


Forum|alt.badge.img+31
  • Honored Contributor
  • August 25, 2021

This is how I do it

```

#!/bin/zsh

if results=$(/opt/snowflake/bin/python3 -V | awk '{print $2}')
then echo "<result>${results}</result>"
else echo "<result>false</result>"
fi

```

 

This way if it fails you have a `false` value and that data is actionable 


donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • August 31, 2021

This is how I do it

```

#!/bin/zsh

if results=$(/opt/snowflake/bin/python3 -V | awk '{print $2}')
then echo "<result>${results}</result>"
else echo "<result>false</result>"
fi

```

 

This way if it fails you have a `false` value and that data is actionable 


Nice, can also pull the major.minor.patch (semver.org), and use a Smart Computer Group to flag any computers that have a python3 version that isn't at the desired version or higher.

For example if you want everyone on 3.9.7 or higher, flag any computers that do not match this regex. This way if someone has a newer version, they don't get rolled back (unless you're enforcing a specific version):

^3\\.9\\.[7-9]|^[4-9]\\.[0-9]\\.[0-9]