Posted on 08-24-2021 06:54 AM
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!
Solved! Go to Solution.
Posted on 08-24-2021 07:35 AM
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
Posted on 08-24-2021 07:35 AM
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
Posted on 08-24-2021 07:46 AM
THANK YOU! That did it.
08-24-2021 09:28 PM - edited 08-24-2021 09:36 PM
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}'
08-24-2021 10:22 PM - edited 08-24-2021 10:25 PM
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
Posted on 08-31-2021 11:43 AM
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]