title: Script not working properly in crontab, but works when I run manually
body: <p>I have this is script set on crontab, which runs each 15 minutes. It mails me correctly with the respective messages, but when the server falls, the restarting command (/usr/share/tomcat5.5/bin/startup.sh) doesn't restart Tomcat, but if I if run this script manually, it restarts!</p>
  
  <pre><code>*/15 * * * * /root/is_site_alive
  </code></pre>
  
  <hr>
  
  <pre><code>#!/bin/bash
  s=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' 'http://www.nononono.com')
  if [ $s == "200" ]; then
     echo 'java is UP' | mail -s "java  is UP" mail@mail.com
  else
     /usr/share/tomcat5.5/bin/startup.sh
     echo 'java is down - Restarting' | mail -s "Restarting" mail@mail.com
  fi
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>When I log the output of a run from crontab it says:</p>
  
  <pre><code>Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
  At least one of these environment variable is needed to run this program
  </code></pre>
  
  <p>But when I run the script manually:</p>
  
  <pre><code>Using CATALINA_BASE:   /usr/share/tomcat5.5
  Using CATALINA_HOME:   /usr/share/tomcat5.5
  Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp
  Using JRE_HOME:        /usr/lib/jvm/java-6-sun/jre
  </code></pre>
  
  <p>Seems the user running crontab doesn't have knowledge of Java paths. Why is this happening? </p>