aspose file tools*
The moose likes Linux / UNIX and the fly likes script to email if tomcat has stopped Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "script to email if tomcat has stopped" Watch "script to email if tomcat has stopped" New topic
Author

script to email if tomcat has stopped

Barbara Norway
Ranch Hand

Joined: Sep 30, 2003
Posts: 150
Hello,

Does anyone have a shell script that checks that tomcat is running and emails if not?

I plan to have cron check at some interval and then mail me if it's down. The part I'm looking for help with is the body of the script.


ps -ef | grep tomcat | wc -l
if {whatever var for wc is}< 2
mail datamaven@anyschool.edu
fi (or endif)


I have heard that when grepping the ps command it is possible to get the grep statement itself as well as the statement one is looking for, but not always. So sometimes the wc will be one or two if tomcat is up. If it's down it could also be one (or zero). So that's the first question I have. The second is: what would the Bourne shell syntax be to accomplish the task?

Thanks in advance for any help.
Barbara aka farmkitty


farmkitty
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

replace your line:

with

grep -v searches for lines, which don't contain a pattern (inVert): pattern 'grep' in this case, so it's filtered out.
grep -c counts the occurences, instead of displaying the match.
grep -q quiet, no output.

Finally we don't need the -c for grep, because it returns true or false.

&& needs no comment to javaian?

The 'mail to@some.one' insn't tested, and as far as I know, you have to use 'mailx' but I don't know the whole syntax - I guess you need a subject, etc. too.
[ June 07, 2004: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
Barbara Norway
Ranch Hand

Joined: Sep 30, 2003
Posts: 150
HI Stefan,
Thanks! I tried it and this helps a lot. In case anyone is using Solaris 8 like I am, I had to use the /usr/xpg4/bin version of grep in order to use the -v flag:
ps -ef | grep tomcat | /usr/xpg4/bin/grep -vqc && mail kitty@catcity.edu

Barbara
Barbara Norway
Ranch Hand

Joined: Sep 30, 2003
Posts: 150
oops...I meant to use the -q flag I needed to use the /usr/xpg4/bin version of grep.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

If you want something more industrial-strength, try Big Brother. It can monitor your server port(s) and display status of multiple services and multiple hosts on a "big board" with drilldown capabilities.


Customer surveys are for companies who didn't pay proper attention to begin with.
Barbara Norway
Ranch Hand

Joined: Sep 30, 2003
Posts: 150
I love big brother ;-) we used it at a place i worked a couple of years ago. I'll have to make the time to install and configure it here!
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: script to email if tomcat has stopped