The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-04-2009
quyennd quyennd is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
Please help to fingure out what wrong with my tomcat restarting bash script

Hi, I am a nbee to Unix, I have used following script to check my tomcat is running or not and restart if it down. but actually it restart my tomcat each time running even my tomcat still running fine:

Script that can run a check and perform an action if the check fails

/root/commandchecker.sh (get from http://downloads.rimuhosting.com/commandchecker.sh)

/root/istomcatrunning.sh:
code:
#!/bin/bash
tomcatpids=`ps axf --width=200 | grep "\-D[j]ava.endorse" | sed 's/^ *//g' | cut -d ' ' -f 1`
if [ -z "$tomcatpids" ]; then
# return a 'fail' code
return 1
fi
return 0

/root/restarttomcat.sh:
Code:
#!/bin/bash
# try to be nice
/etc/rc.d/init.d/tomcat stop
# but sometimes more drastics measures are necessary if things are not responding
kill -9 `ps axf --width=200 | grep "\-D[j]ava.endorse" | sed 's/^ *//g' | cut -d ' ' -f 1`
/etc/rc.d/init.d/tomcat start

cron job.

/etc/cron.d/monitortomcat.cron
0-59/5 * * * * root /root/commandchecker.sh --email youremail@example.com --command "/root/istomcatrunning.sh" --onfail "/root/restarttomcat.sh" --triggeractionafternfails 3 --checkname tomcatcheck > /dev/null"


The error I get when script run:
/root/istomcatrunning.sh: line 5: return: can only `return' from a function or sourced script
/root/istomcatrunning.sh: line 7: return: can only `return' from a function or sourced script
failed command result match (25 recently) for '/root/istomcatrunning.sh' expecting ''. recode=1
taking some action: /root/restarttomcat.sh
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
startup taking too long, not getting a response on The UNIX and Linux Forums - Learn UNIX and Linux from Experts, giving up
command result mismatch for /root/istomcatrunning.sh, sending email

Could anyone help to fingure out what wrong with the script please?

Thx a lot.
Quyen Nguyen.