#!/bin/bash
#
#  Confirm Tomcat server is running and working properly
#  Requires: tomcat6
#

# Check tomcat is running
run1=`netstat -ltnp | grep '8080' | grep 'java'`
if [ -z "$run1" ]; then
  echo "FAIL: Tomcat is not running."
  exit 1
fi

# Check if Tomcat is working; requires network connection so check it
check=`ping -c 2 www.ubuntu.com |grep "2 received"`
if [ -n "$check" ]; then
  work1=`w3m http://127.0.0.1:8080 | grep "works"`
  if [ -z "$work1" ]; then
    echo "FAIL: Tomcat is not working properly."
    exit 1
  fi
fi

exit 0
