Posted on 03-01-2012 01:32 PM
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
Solved! Go to Solution.
Posted on 03-01-2012 02:11 PM
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
Posted on 03-01-2012 02:11 PM
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
Posted on 03-01-2012 04:01 PM
Works! Thanks Sean!
Posted on 04-16-2012 11:55 AM
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
Posted on 04-17-2012 10:38 AM
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
Posted on 07-16-2012 05:54 PM
@kevindigg, that EA is working great, thanks for the contribution.
Posted on 07-17-2012 07:57 AM
i'm using this:
#!/bin/bash
echo "<result>`/usr/bin/java -version 2>&1 > /dev/null | awk '/version/ {gsub(/[""]/,""); print $NF}'`</result>"
Posted on 09-05-2012 12:32 PM
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!
Posted on 09-05-2012 01:03 PM
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.
Posted on 09-11-2012 01:29 PM
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
Posted on 09-11-2012 01:38 PM
@Don
You thought so too? :-)
Posted on 09-11-2012 01:42 PM
@ 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.
Posted on 09-11-2012 02:03 PM
@mm2270 I must have scrolled right past that! :(
Thanks!
Posted on 01-11-2013 08:24 PM
nm. :)
Posted on 01-12-2013 12:00 AM
@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
Posted on 01-12-2013 03:11 AM
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-browse...
Posted on 02-14-2013 07:45 AM
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
Posted on 02-15-2013 12:45 AM
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...
Posted on 02-20-2013 07:01 AM
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.
Posted on 02-20-2013 07:09 AM
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
Posted on 02-20-2013 07:19 AM
So is Apple updating Java again or do I still need to go get Java SE Runtime Environment 7u15 from Oracle or both?
Thanks.
Posted on 02-20-2013 07:32 AM
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.
Posted on 02-20-2013 07:40 AM
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.
Posted on 02-20-2013 09:04 PM
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
--------------
Posted on 08-20-2013 11:32 AM
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>"
#####################################################################
Posted on 01-22-2014 06:17 AM
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?
Posted on 01-22-2014 06:33 AM
#!/bin/bash
echo "<result>`/usr/bin/java -version 2>&1 > /dev/null | awk '/version/ {gsub(/[""]/,""); print $NF}'`</result>"
Posted on 01-22-2014 06:50 AM
that just reported
1.7.0_51
Which is what I am running into
Posted on 01-22-2014 07:51 AM
what do you get when you go into terminal and type: /usr/bin/java -version
Testing on a 10.8.5 machine with both Java 1.7.0_51 (from oracle) and Java 1.6.0_65 (from apple) it returns the 1.6.0_65 info.
Posted on 01-22-2014 07:59 AM
you need to realize that the 1.6.0 java from oracle by default is only the SDK part not the internet plugin. they are two separate pieces. Most likely if you have installed what the java.com web page points you to its only the internet plugin. you have to get the 1.7 SDK from elsewhere the plugin pkg is named "Java 7 Update 51.pkg" and the JDK is named "JDK 7 Update 51.pkg"
Posted on 01-22-2014 08:00 AM
sorry 1.6.0 in the first sentence should be 1.7.0
Posted on 01-22-2014 08:58 AM
Mine returns -
/usr/bin/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode
Is it possible that if JDK 7 is installed, it doens't install Apples?
Posted on 01-22-2014 02:55 PM
@jwojda
You have JDK 7 installed and JDK comes with JRE (internet plug-in) as well.
If you want Apple Java 6 (with JDK and JRE), please downland and install the latest Java update from apple (e.g.- Java for OS X 2013-005). Also you will have to uninstall Java 7 JDK and JRE first.
Posted on 03-14-2014 02:18 PM
I tried this script s Extension Attribute.
#!/bin/sh
echo "<result>java -version
</result>"
I and then update my inventory. when I look in my inventory nothing is showing up for the result of the script. How is the best way to report on java version?
Posted on 03-17-2014 11:23 AM
Based on what @rtrouton][/url had already submitted for an extension attribute, I'm submitting this one today that goes a little further and also gets the version. It's always good to look under the Third-Party section of the Nation to see if this stuff exists there. Here's Java's:
https://jamfnation.jamfsoftware.com/viewProduct.html?id=229&view=info
And here's my script I'm submitting below. Use at your own risk and test. As with other extension attributes, if your users have admin rights to their box and you're not stopping them from upgrading things like Flash, Flip4Mac, SilverLight, and Java on your own you can't really base your smart groups on the last installed Casper Package of those installed by you. You really need to use an extension attribute that see what version is really installed and then base smart groups and policies on that. Just my opinion.
#!/bin/sh
# Java_Vendor_and_Version.sh
#
# Original version for vendor by Richard Trouton on 5/8/13.
# Modified to include version by Craig Ernst on 3/17/14.
# Tested on Mac OS X 10.8 and 10.9
#
# Keep in mind that on a clean install of 10.8 the command 'java -version'
# will prompt to install Apples old version of Java SE 6 if not installed,
# and that 'java -version' will not give the true Internet Plug-In version.
# Even after installing an Oracle version of Java that version info is not updated.
#
# Also keep in mind that on 10.9 the command 'java -version' behaves similarly.
# Although instead of a prompt to install Apple's version it will direct you
# to Oracle's website.
#
# If reporting no Java or an Apple version you should consider installing
# an Oracle version as Apple no longer updates Java.
#
#!/bin/bash
javaVendor=`/usr/bin/defaults read /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info CFBundleIdentifier`
javaVersion=`/usr/bin/defaults read /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info CFBundleVersion`
if [ "$javaVendor" = "com.oracle.java.JavaAppletPlugin" ]; then
result="Oracle $javaVersion"
elif [ "$javaVendor" = "com.apple.java.JavaAppletPlugin" ]; then
result="Apple $javaVersion"
elif [ "$javaVendor" = "" ]; then
result="No Java Plug-In Available"
fi
echo "<result>$result</result>"