At first I find a shell script from internet
#!/bin/sh
#kill tomcat pid
pidlist=`ps -ef|grep tomcat | grep -v "grep"|awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
echo "tomcat Id list :$pidlist"
if [ "$pidlist" = "" ]
then
echo "no tomcat pid alive"
else
for pid in ${pidlist}
{
kill -9 $pid
echo "KILL $pid:"
echo "service stop success"
}
fi
I can run this script, but crontab run it show me a error: "{" unexpected (expecting "do")
so I change according this error and delete some echo because system will sent these echo to me with mail, it's boring
# !/bin/bash
# kill tomcat pid and restart tomcat
pidlist=`ps -ef| grep pache-tomcat-6.0.20-dev| grep -v "grep"|awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
if [ "$pidlist" != "" ]
then
for pid in ${pidlist}
do
kill -9 $pid
done
#start tomcat
/opt/apache-tomcat-6.0.20-dev/bin/startup.sh
fi
tips:at first I delete echo "no tomcat pid alive" and there is nothing after then, it is not allowed
#!/bin/sh
#kill tomcat pid
pidlist=`ps -ef|grep tomcat | grep -v "grep"|awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
echo "tomcat Id list :$pidlist"
if [ "$pidlist" = "" ]
then
echo "no tomcat pid alive"
else
for pid in ${pidlist}
{
kill -9 $pid
echo "KILL $pid:"
echo "service stop success"
}
fi
I can run this script, but crontab run it show me a error: "{" unexpected (expecting "do")
so I change according this error and delete some echo because system will sent these echo to me with mail, it's boring
# !/bin/bash
# kill tomcat pid and restart tomcat
pidlist=`ps -ef| grep pache-tomcat-6.0.20-dev| grep -v "grep"|awk '{print $2}'`
#ps -u $USER|grep "java"|grep -v "grep"
if [ "$pidlist" != "" ]
then
for pid in ${pidlist}
do
kill -9 $pid
done
#start tomcat
/opt/apache-tomcat-6.0.20-dev/bin/startup.sh
fi
tips:at first I delete echo "no tomcat pid alive" and there is nothing after then, it is not allowed