nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Tomcat shell script cron job to restart server

This is a discussion on Tomcat shell script cron job to restart server within the Shell scripting forums, part of the Development/Scripting category; i am suffering through a shell script prob. when i am running my shell script using "sh" it is working ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-01-2008, 12:52 PM
Member
User
 
Join Date: Jul 2006
Posts: 72
Rep Power: 0
kasimani
Send a message via Yahoo to kasimani
Default Tomcat shell script cron job to restart server

i am suffering through a shell script prob. when i am running my shell script using "sh" it is working fine, but when i put that file inn crontab, it's stops running.
i am giving u my script, actually this script will stop and aging restart the tomcat server.

if [ `netstat -nlp | grep :3128 | wc -l` = 1 ]; then
{
echo live
kill -9 `ps -ef|grep java|awk '{print $2}'`
}
fi
sleep 5
cd /usr/local/apache-tomcat-6.0.13/
sh ./bin/startup.sh > err.txt


in err.txt i got this message

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



i just check the startup.sh script i found that is starting with

#!/bin/sh

is this a problem, well i am inn /bin/bash, but this doesn't helped me out.

pl. help me out of this problem

Thanks in Advance

Last edited by kasimani; 05-02-2008 at 11:23 AM. Reason: symble
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-02-2008, 08:58 PM
agn agn is offline
Member
User
 
Join Date: Feb 2008
My distro: OpenBSD/FreeBSD/Debian/Fedora/RHEL
Posts: 69
Rep Power: 1
agn is on a distinguished road
Default

Set the necessary env variables in crontab or in your script. cron( has a very limited env by default.
Reply With Quote
  #3 (permalink)  
Old 05-03-2008, 12:28 PM
Member
User
 
Join Date: Jul 2006
Posts: 72
Rep Power: 0
kasimani
Send a message via Yahoo to kasimani
Default java home in cron

can u pl. tell me how to set ENV variable to set java home or JRE home in cron

Thanks in Advance

Last edited by kasimani; 05-03-2008 at 12:35 PM.
Reply With Quote
  #4 (permalink)  
Old 05-03-2008, 02:02 PM
Member
User
 
Join Date: Jul 2006
Posts: 72
Rep Power: 0
kasimani
Send a message via Yahoo to kasimani
Default solved

thanks a tone for giving solution, this is such a little thing that i did not knew.

Thanks for giving support
Reply With Quote
  #5 (permalink)  
Old 05-03-2008, 07:46 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 910
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You can add variable to /etc/crontab

Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.5.0_07/bin
MAILTO=root
HOME=/home/admin/
JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
Alternatively, add it your script itself
Code:
#!/bin/bash
export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
if [ `netstat -nlp | grep :3128 | wc -l` = 1  ]; then
{
echo live
kill -9 `ps -ef|grep java|awk '{print $2}'`
}
fi
sleep 5
cd /usr/local/apache-tomcat-6.0.13/
sh ./bin/startup.sh > err.txt
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks

Tags
cronjobs , crontab , linux , redhat , shell script , tomcat


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Nagios on tomcat? Vince-0 Linux software 0 04-22-2008 01:30 PM
Shell Script to Automatically Delete a File via Cron Job kakarla Shell scripting 2 01-29-2008 08:54 AM
Shell script to perform operation on remote server vivekv Shell scripting 3 10-24-2007 12:10 AM
writing a shell script to find out my shell name jaymob123 Shell scripting 1 10-08-2007 12:36 AM
Require Shell Script Which sends all server info on mail puppen Linux software 3 10-25-2006 08:07 PM


All times are GMT +5.5. The time now is 04:45 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36