I'm trying to write a shell script which uses a command called jmxquery
This is what works on the command line:
[root@monitor jmxquery]# java -jar /opt/jmxquery/jmxquery.jar \
-U service:jmx:rmi:///jndi/rmi://tomcat.cyberdyne.corp:1099/jmxrmi \
-O java.lang:type=GarbageCollector,name='PS MarkSweep' \
-A LastGcInfo \
-K GcThreadCount
**JMX OK - LastGcInfo.GcThreadCount=4 | LastGcInfo.GcThreadCount=4**
As you can I see i get a JMX OK with thread count details. So I'm trying to do the same within a shell script. I have a variables defined like this:
JAR=/opt/jmxquery/jmxquery.jar
JMXHOST=tomcat.cyberdyne.corp
JMXPORT=1099
SERVICE_URL="service:jmx:rmi:///jndi/rmi://${JMXHOST}:${JMXPORT}/jmxrmi"
attr_marksweep_threadcount="-O java.lang:type=GarbageCollector,name='PS MarkSweep' -A LastGcInfo -K GcThreadCount"
Then I run:
java -jar ${JAR} -U ${SERVICE_URL} $attr_marksweep_threadcount
Here is a snippet of what the output looks like with bash -x
+ attr_marksweep_threadcount='-O java.lang:type=GarbageCollector,name='\''PS MarkSweep'\'' -A LastGcInfo -K GcThreadCount'
+ java -jar /opt/jmxquery/jmxquery.jar -U service:jmx:rmi:///jndi/rmi://spotfirewin75.cyberdyne.corp:1099/jmxrmi -O 'java.lang:type=GarbageCollector,name='\''PS' 'MarkSweep'\''' -A LastGcInfo -K GcThreadCount
**JMX CRITICAL - java.lang:type=GarbageCollector,name='PS**
As you can see it's chopped off the rest of the command after PS.
How do I get the script to substitute correctly?
${SERVICE_URL}
being defined anywhere.