title: Running unix command through tomcat
body: <p>I am running a script containing the following commands </p>
  
  <p><code>#!/bin/bash
  ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'</code></p>
  
  <p>I have a java wrapper for executing this script using Runtime.exec(...). Running this java code works fine all the time.</p>
  
  <p>The problem is when using running this java method under tomcat it give me an error<br>
  <code>script.sh: line 3: ifconfig: command not found</code><br>
  Restarting the tomcat service the script runs perfectly for some time, after which this problem is again persists. </p>
  
  <p>How do i solve this problem ?</p>
  
  <p>EDIT : 
  Java code :</p>
  
  <pre><code>String executableScript = &lt;path to script&gt;/script.sh;
  String line;
  String output;
  String[] command = {executableScript};
  Process process = Runtime.getRuntime().exec(command);
  BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
  while ((line = input.readLine()) != null) {
      output.append(line);
  }
  process.waitFor();
  input.close();
  </code></pre>