title: Nagios: trying to run custom command return 126
body: <p>I'm trying to get Nagios to execute a custom java command but I always get error 126.</p>
  
  <pre><code>[1360324906] Warning: Return code of 126 for check of service 'Java Process Test' on host 'localhost' was out of bounds.Make sure the plugin you're trying to run is executable.
  </code></pre>
  
  <p>Now I've checked few things but as I'm a newbie here I probably missed something.
  Here few information about the environment:</p>
  
  <pre><code>-rwxr-xr-x. 1 root root     2938 Aug 17 15:39 check_wave
  drwxr-xr-x. 2 root root     4096 Jan 13 15:08 eventhandlers
  drwxr-xr-x. 2 root root     4096 Feb  7 17:22 jars
  -rwxr-xr-x. 1 root root    38696 Aug 17 15:39 negate
  -rwxr-xr-x. 1 root root      886 Feb  8 12:47 test_java_plugin.sh
  </code></pre>
  
  <p>test_java_plugin.sh is my test script and "jars" is the current dir where the jar is located</p>
  
  <p>Scripts is this:</p>
  
  <pre><code>#!/bin/bash
  
  #This will get the output of process
  output=$(/usr/java/latest/bin/java -cp .:/usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest)
  #This will catch the result returned by last process that is our java command
  java_result=$?
  echo "$java_result: $output"
  exit $java_result
  </code></pre>
  
  <p>and is working perfectly when launched manually at console</p>
  
  <pre><code>[root@bw plugins]# ./test_java_plugin.sh 
  0: This is an OK message
  </code></pre>
  
  <p>Forgot to add command definition:</p>
  
  <pre><code># 'test_java_plugin' command definition
  define command{
          command_name   test_java_plugin
          command_line   $USER1$/test_java_plugin.sh
          }
  </code></pre>
  
  <p>Also as as per request into comment I'm adding also the current java code of my test class</p>
  
  <pre><code>public static void main(String[] args) {
      System.out.println("This is an OK message");
      System.exit(0);
  }
  </code></pre>
  
  <p>Just launching the command from a shell I got still 0:</p>
  
  <pre><code>[root@bw plugins]# /usr/java/latest/bin/java -cp .:/usr/lib64/nagios/plugins/jars/SimpleNagiosPlugin.jar it.nagios.SimpleTest
  This is an OK message
  [root@bw plugins]# echo $?
  0
  </code></pre>
  
  <p>What else should I check to determine what is going wrong here?</p>