Please help to fingure out what wrong with my tomcat restarting bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help to fingure out what wrong with my tomcat restarting bash script
# 1  
Old 01-04-2009
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.
# 2  
Old 01-05-2009
Quote:
Originally Posted by quyennd
The error I get when script run:
/root/istomcatrunning.sh: line 5: return: can only `return' from a function or sourced script

Read the error message!

Either source the scripts or change return to exit.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Restarting shell script in case of a failure

I have a shell script which sqoops data from one place to hive and it does in 2 groups list. If one group is completed it waits for the second to get completed then goto to orc load, but it it fails it kills the other groups and sends a fail email. What I was looking for is if 1 group fails, it... (1 Reply)
Discussion started by: Kunalcurious
1 Replies

2. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

3. Shell Programming and Scripting

What's wrong with my bash code?

I want to let sleep 3 in the background and echo $i pkglists="a b c d e f g" f() { local i set -- $pkglists && ((i +=2)) && sleep 3 &;echo $i } f (3 Replies)
Discussion started by: yanglei_fage
3 Replies

4. Shell Programming and Scripting

Bash conditional | getting logic wrong?

I have a file cat <<EOF > /tmp/test Line one Line two Line three EOF Now I am trying to get the exit stat ($?) of 1 if any text is found and 0 if any text is not found using grep, i.e. just reversing the exit status of grep # (snippet 1) this one is not working!!! retval $?... (4 Replies)
Discussion started by: the_gripmaster
4 Replies

5. Solaris

Tomcat..Unable to deploy application remotely in tomcat

Hi, We have upgrade tomcat from 5.0.20 to 7.0.33 and made changes to server.xml file according to newer version.. how ever the upgrade went fine and now i am unable to deploy application remotely.. it is giving 403 access denied error.. we have seperate appbase directory mentioned in server.xml..... (0 Replies)
Discussion started by: phani4u
0 Replies

6. Shell Programming and Scripting

Script for to kill the process Ids when restarting the unix server

Hi, I need a script to kill the process Ids for the user ABC. I prepared the following script after that while logging with user therough script i am not sure how to pass the user name and password.Can ou modify the script and help me out. #!/bin/bash for filesize in $(ls -ltr | grep... (4 Replies)
Discussion started by: victory
4 Replies

7. UNIX for Advanced & Expert Users

Append password on script when restarting web instance

im writing a start/stop script for a web instance (solaris) . Currently I usually start it using the command below and it will ask me to put the token password for the web_instance. (token pw: 12345) /opt/SUNWwbsvr/https-www.myhost.com/start I would like to create a script that... (4 Replies)
Discussion started by: lhareigh890
4 Replies

8. Shell Programming and Scripting

How to check for and start the Tomcat using a script

Hello Everyone,. I am a novice with shell scripting and have written some minor shell scripts to copy files and such that. Now I have a requirement to write a shell script to go check if Tomcat running in the same server is up or not, if not then run the Tomcat startup script. Then put this... (4 Replies)
Discussion started by: bhaire
4 Replies

9. Shell Programming and Scripting

what's wrong with my bash script?

hi, please point out what's wrong with my script. im feeding it a list containing fqdn, sit should ssh into each and verify that atleast one of its virtual backup ip resolves into one of its virtual hostnames .. anyway the objective shows in the script... however, im having problems in the ... (4 Replies)
Discussion started by: ikk
4 Replies

10. Shell Programming and Scripting

Bash passes flags to shell wrong

Hi, first post, so hello to all. I have a Bash scripting problem that is driving me a bit nutty. It involves a program called 'convert' which is part of the ImageMagick collection. Normal usage from the commandline is: $ convert -resize 120x120 inputfile.jpg outputfile.jpg This is... (7 Replies)
Discussion started by: andyj
7 Replies
Login or Register to Ask a Question