Calling JMX MBean method from a shell script

The following command line JMX utilities are available:

  1. jmxterm – seems to be the most fully featured utility.
  2. cmdline-jmxclient – used in the WebArchive project seems very bare bones (and no development since 2006 it looks like)
  3. Groovy script and JMX – provides some really powerful JMX functionality but requires groovy and other library setup.
  4. JManage command line
    functionality – (downside is
    that it requires a running JManage
    server to proxy commands through)

Groovy JMX Example:

import as JmxFactory
import as JmxUrl

def serverUrl="service:jmx:rmi:///jndi/rmi://localhost:9003/jmxrmi"
String beanName = ",id=0"
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection
def dataSystem = new GroovyMBean(server, beanName)

println "Connected to:\n$dataSystem\n"

println "Executing jmxForceRefresh()"

cmdline-jmxclient example:

If you have an

  • MBean:,id=0

With an Operation called:

  • jmxForceRefresh()

Then you can write a simple bash script (assuming you download cmdline-jmxclient-0.10.3.jar and put in the same directory as your script):



#No User and password so pass '-'
echo "Available Operations for,id=0"
java -jar ${cmdLineJMXJar} ${user}:${password} ${jmxHost}:${port},id=0

echo "Executing XML update..."
java -jar ${cmdLineJMXJar} - ${jmxHost}:${port},id=0 jmxForceRefresh

Leave a Comment