Skip to main content

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!

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

THANK YOU! That did it.


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

 

 

 

 

 

 


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 


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]