Skip to main content
Solved

Collect Java version - Inventory - Extension Attribute


Forum|alt.badge.img+6

Anyone have a good method or suggestion on how to collect Java version on clients?

My method (which isn't working) was I wrote an extension attribute. But...even though the command works manually on the client, no information is collected in the JSS.

I've verified that the client is executing the Extension Attribute by examining an output file after performing Recon (sudo jamf recon -saveFormTo /pathtofile). I see my other Extension Attributes - and I see that it runs the Java attribute - but no information is being collected.

Here is my attribute:
Data Type: String
Input Type: Populated By Script

#!/bin/sh
echo "<result>java -version</result>"

When run locally (manually) you get this output:
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

Any ideas on the best way to get the Java version in Inventory? Thanks!

Sean

Best answer by sean

Sean

I would suggest that if you run it locally it doesn't work and the output is:

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
<result></result>

Notice the result tags at the end. Try this instead:

#!/bin/bash
echo -n "<result>"
java -version
echo "</result>"

The output should then look like:

<result>java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
</result>

Sean

View original
Did this topic help you find an answer to your question?

34 replies

Forum|alt.badge.img+12
  • Contributor
  • 529 replies
  • Answer
  • March 1, 2012

Sean

I would suggest that if you run it locally it doesn't work and the output is:

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
<result></result>

Notice the result tags at the end. Try this instead:

#!/bin/bash
echo -n "<result>"
java -version
echo "</result>"

The output should then look like:

<result>java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03-384-10M3425)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-384, mixed mode)
</result>

Sean


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 10 replies
  • March 2, 2012

Works! Thanks Sean!


Forum|alt.badge.img+4

I'm running the below script as an extension attribute, but for machines that don't have java installed, they get that blasted popup in LION asking them to install java. Any ideas on how I can check the version on a client without java and if it's null do not prompt to install.

#!/bin/sh

#Redirecting complete output of java -version to tmp.txt file
java -version >tmp.txt 2>&1

#Getting current version from the tmp.txt file
VERSION=cat tmp.txt | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'

if [[ -z "$VERSION" ]]
then echo "<result>" "java not installed" "</result>"
else echo "<result>" "java" $VERSION "</result>"
fi

rm tmp.txt


kevindigg
Forum|alt.badge.img+3
  • New Contributor
  • 10 replies
  • April 17, 2012

After borrowing your version extraction line, I think I've got a way to bypass the pop-up in lion. I need to do a little more testing, but see if this works for you:

EDIT:

The following seems to be working for us as an extension attribute:

#!/bin/bash

#Check if java_home is defined
javaHome=/usr/libexec/java_home 2> /dev/null;

if [ ! -z $javaHome ]
then vers=java -version 2>&1 | grep "java version" | awk '{print substr($3,2,length($3)-2);}' echo "<result>$vers</result>"
else echo "<result>Not Installed</result>"
fi


  • 0 replies
  • July 17, 2012

@kevindigg, that EA is working great, thanks for the contribution.


Forum|alt.badge.img+13

i'm using this:

#!/bin/bash
echo "<result>`/usr/bin/java -version 2>&1 > /dev/null | awk '/version/ {gsub(/[""]/,""); print $NF}'`</result>"

Forum|alt.badge.img+6
  • Contributor
  • 49 replies
  • September 5, 2012

Is Kevin's EA still working for folks? I have done a manual test via terminal but wanted to get confirmation before this is deployed to production machines.
Thanks for any feedback!


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • September 5, 2012

Our's looks like this, which just pulls the short version string, and not all that other info-

#!/bin/sh

if [[ -e /Library/Java/Home ]]; then
    echo "<result>$(java -version 2>&1 | awk '/version/{print $3}' | sed 's/"//g')</result>"
        else
    echo "<result>Java not installed</result>"
fi

In testing, it does not prompt 10.7 or 10.8 Macs with no Java installed to install it.

Kevin's looks like it works fine as well. Many ways to skin the same cat.


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • September 11, 2012

Great solutions!

How do we get the Extension Attribute to report "No" if Java is not installed?

We are testing SEP12.1 and so far so good...except that it requires Java to be installed. Ironic, no? :)

Don


talkingmoose
Forum|alt.badge.img+36
  • Community Manager
  • 1901 replies
  • September 11, 2012

@Don

You thought so too? :-)


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • September 11, 2012

@ Don, see the one I posted above. In the if/then conditional I echo back "Java not installed" if the "/Library/Java/Home" directory is not found. You can change the echo to "No" and get the same result.
That's only one example. I'm sure there are several approaches that will all work.


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • September 11, 2012

@mm2270 I must have scrolled right past that! :(

Thanks!


Forum|alt.badge.img+1

nm. :)


donmontalvo
Forum|alt.badge.img+36
  • Legendary Contributor
  • 4293 replies
  • January 12, 2013

@ableengineering wrote:

not sure I get it: i created a new extension attribute in inventory preferences. selected input type populated by script. when i try to run an inventory report using it, it's asking for to match criteria that i guess I don't know. how is this supposed to work? sorry for noob question. thanks.

If you can post your Extension Attribute you might get some responses. :)

Don


Forum|alt.badge.img+23
  • Esteemed Contributor
  • 850 replies
  • January 12, 2013

jamfnation user rtrouton has a funky script that I've adapted for use. You can find his original script at http://derflounder.wordpress.com/2012/10/31/casper-extension-attribute-scripts-to-report-java-browser-plug-in-info/


Chris_Hafner
Forum|alt.badge.img+23
  • Jamf Heroes
  • 1718 replies
  • February 14, 2013

This is another alternate post that gives a very similar solution to what we're using.
https://jamfnation.jamfsoftware.com/discussion.html?id=5641#respond


Forum|alt.badge.img+9

I run the script that some others have implemented as well that franton is using.
I populate this by Script and the date type is String.

#!/bin/bash # Christoph von Gabler-Sahm (email-redacted) # Version 1.0 # checks installed version of Java Applet Plugin # returns values like "Not installed", "JavaInstallOnDemand: 14.5.0", "JavaJDK16: 14.5.0" or "Java 7 Update 09" PLUGINPATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" # Plugin version S_VERSION=$( /usr/bin/defaults read "${PLUGINPATH}/Contents/Info" CFBundleShortVersionString 2>/dev/null ) # JavaInstallOnDemand or empty S_PROJECT=$( /usr/bin/defaults read "${PLUGINPATH}/Contents/version" ProjectName 2>/dev/null ) if [[ -e "${PLUGINPATH}" ]]; then if [[ "${S_PROJECT}" == "" ]]; then EA_RESULT="${S_VERSION}" else EA_RESULT="${S_PROJECT}: ${S_VERSION}" fi else EA_RESULT="Not installed" fi echo "<result>${EA_RESULT}</result>"

The Java Version is not shown.
But I can retrieve the vendor information with the script from derflounder...


Forum|alt.badge.img+12
  • Valued Contributor
  • 143 replies
  • February 20, 2013

OK. I have scripts running for version checking and vendor info, yet I need help with the results. In my office I have a mix of 10.6, 10.7, and 10.8 machines which are currently in the process of moving all to 10.8.2/3 once I figure out Casper imaging... Anyway, I need help figuring out what the different results mean to easily tell which version is latest for the Mac versions as "JavaInstallOnDemand" doesn't reflect the ASUS versions...
OS | Vendor | Version
1. Mac OS X 10.8.2 | Apple | JavaInstallOnDemand: 14.5.0 (what is this?)
2. Mac OS X 10.6.8 | Apple | JavaInstallOnDemand: 13.9.0 (This is JavaForMacOSX10.6-12.0/Java for Mac OS X 10.6 Update 12)
5. Mac OS X 10.6.8 | Apple | JavaInstallOnDemand: 13.9.2 (This is JavaForMacOSX10.6-13.0/Java for Mac OS X 10.6 Update 13)
Is there a place that lists JavaInstallOnDemand versions as they relate to ASUS list?
Thanks for any assistance.


Forum|alt.badge.img+31
  • Employee
  • 920 replies
  • February 20, 2013

I don't know of a list, but here's what the following statuses correspond to:

10.7.x - 10.8.x | Apple | JavaInstallOnDemand: 14.5.0 - Corresponds to Java for OS X 2012-006
10.7.x - 10.8.x | Apple | JavaInstallOnDemand: 14.6.0 - Corresponds to Java for OS X 2013-001


Forum|alt.badge.img+12
  • Valued Contributor
  • 143 replies
  • February 20, 2013

So is Apple updating Java again or do I still need to go get Java SE Runtime Environment 7u15 from Oracle or both?
Thanks.


Forum|alt.badge.img+31
  • Employee
  • 920 replies
  • February 20, 2013

Depends, do you need Java running in a web browser on your 10.7 / 10.8 Macs? Apple's Java for OS X 2012-006 and Java for OS X 2013-001 both remove the Apple Java browser plug-in.

Apple's handing off Java to Oracle, so Oracle's Java 7 Update 15 installs a Java browser plug-in on Macs running 10.7.3 and higher.


Forum|alt.badge.img+12
  • Valued Contributor
  • 143 replies
  • February 20, 2013

I see that now. I RTFM here.

About Java for OS X 2013-001 This release updates the Apple-provided system Java SE 6 to version 1.6.0_41 and is for OS X versions 10.7 or later. This update uninstalls the Apple-provided Java applet plug-in from all web browsers. To use applets on a webpage, click on the region labeled "Missing plug-in" to go download the latest version of the Java applet plug-in from Oracle. This update also removes the Java Preferences application, which is no longer required to configure applet settings.

I don't want to hijack this thread any further so I'll start a new thread. Thanks for your help.


Forum|alt.badge.img+13
  • Contributor
  • 400 replies
  • February 21, 2013

This is the script I use which I grabbed bits and pieces from other scripts and edited

#!/bin/bash

javaPluginPath="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
javaVendor=`/usr/bin/defaults read "${javaPluginPath}/Contents/Info" CFBundleIdentifier`

if [[ "$javaVendor" =~ "com.oracle.java." ]]; then
        vers=`/usr/bin/defaults read "${javaPluginPath}/Contents/Info" CFBundleVersion 2>/dev/null`

elif [[ "$javaVendor" =~ "com.apple.java." ]] && [[ -L /Library/Java/Home ]]; then
     vers=`java -version 2>&1 | grep "Runtime Environment" | awk '{print substr($6,1,length($6)-9);}'`        

else
     vers="Not Available"
fi

echo "<result>$vers</result>"

This will return (on OS X 10.8.2):

Java 6
Java Plug-In Version:1.6.0_35-b10-428

Java 7
Java Plug-In Version:1.7.15.03

We use this format so we can easily cross check with XProtect settings.

--------------
* Script update 02 Jul 2013
--------------


  • 0 replies
  • August 20, 2013

I use two scripts, one to pull the Java 6 version and another for the Java 7. This allows me to create a smart group and filter what machine needs to be upgraded.

#####################################################################
Java 6 #####################################################################
#!/bin/bash

if [[ -L /Library/Java/Home ]]; then
vers=java -version 2>&1 | grep "Runtime Environment" | awk '{print substr($6,1,length($6)-9);}'

else
vers="Not Available"
fi

echo "<result>$vers</result>"
#####################################################################

#####################################################################
Java 7
#####################################################################
#!/bin/bash

javaPluginPath="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
javaVendor=/usr/bin/defaults read "${javaPluginPath}/Contents/Info" CFBundleIdentifier

if [[ "$javaVendor" =~ "com.oracle.java." ]]; then
vers=/usr/bin/defaults read "${javaPluginPath}/Contents/Info" CFBundleVersion 2>/dev/null

elif [[ "$javaVendor" =~ "com.apple.java." ]] && [[ -L /Library/Java/Home ]]; then
vers=java -version 2>&1 | grep "Runtime Environment" | awk '{print substr($6,1,length($6)-9);}'

else
vers="Not Available"
fi

echo "<result>$vers</result>"
#####################################################################


ImAMacGuy
Forum|alt.badge.img+23
  • Esteemed Contributor
  • 1310 replies
  • January 22, 2014

I'm trying to get a report on Apple's Java version on the boxes, and I've used a few of the EAs on JN, but they all seem to report Java7 versions now. Anybody have an EA that will tell me which version of J6 is on a box?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings