linux_root_scripts

wangzhensheng發表於2009-02-10

start.sh

stop.sh

app_bin.sh

appo_log.sh

mysql_bin.sh

[@more@]

#################cat start.sh
#!/bin/sh
APP="$1"

if [ "${APP}" == "mysql" ]; then
db_pid="`ps -ef | grep mysql-max/bin/mysqld |grep -v grep| awk '{print $2}'`"
if [ "${db_pid}" != "" ]; then
echo "mysql Started ..."
exit 1
fi
# startup mysql
su - mysql<cd ./mysql-max/
./bin/mysqld_safe &


EOF
elif [ "${APP}" == "tomcat" ] ; then
app_pid="`ps -ef |grep java | grep Djava.awt.headless=true | grep -v grep| awk '{print $2}'`"
if [ "${app_pid}" != "" ]; then
echo "tomcat Started ..."
exit 1
fi
# startup tomcat, port 80
export JAVA_HOME=/usr/java
export JAVA_OPTS='-Xms1024m -Xmx1600m -Djava.awt.headless=true -XX:PermSize=128M -XX:MaxPermSize=256m'
export LANG=zh_CN.GBK
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib

cd /app/tomcat/bin/
./startup.sh

else
echo "`basename $0` using: `basename $0` mysql|tomcat"
exit 1
fi
################# cat stop.sh
#!/bin/sh
APP="$1"

if [ "${APP}" == "mysql" ]; then
db_pid="`ps -ef | grep mysql-max/bin/mysqld |grep -v grep| awk '{print $2}'`"
if [ "${db_pid}" == "" ]; then
echo "mysql Stoped ..."
exit 1
fi
# stop mysql
su - mysql<cd ./mysql-max/
echo "stop mysql ..."
./bin/mysqladmin -u root shutdown && echo "mysql stop ..."

EOF
elif [ "${APP}" == "tomcat" ] ; then
app_pid="`ps -ef |grep java | grep Djava.awt.headless=true | grep -v grep| awk '{print $2}'`"
if [ "${app_pid}" == "" ]; then
echo "tomcat Stoped ..."
exit 1
fi
# stop tomcat, port 80
echo "Killed tomcat java ..."
kill -9 ${app_pid} && echo "tomcat java is Killed ..."

else
echo "`basename $0` using: `basename $0` mysql|tomcat"
exit 1
fi

############cat sbin/mysql_bin.sh
#!/bin/sh
DATE=`date +%w`
APP_BAK="/data/backup/app/mysql"
bak_file="mysql_${DATE}.tar.Z"

if [ ! -s "${APP_BAK}/${bak_file}" ] ; then
echo "${APP_BAK}/${bak_file} not exsit ..."
echo "Start backup Mysql to ${APP_BAK}/"
cd /app/
echo "tar mysql directory ..."
echo ""
tar cvf ${APP_BAK}/mysql_${DATE}.tar ./mysql/ && echo "mysql tar is ok ..."
cd ${APP_BAK}/
rm -rf ./mysql_${DATE}.tar.Z
echo "compress mysql tar ..."
compress mysql_${DATE}.tar && echo "mysql tar.Z is ok"
else
echo "${APP_BAK}/${bak_file} is exsit ..."
echo "exit backup script ..."
fi


#################cat app_bin.sh
#!/bin/sh
DATE=`date +%w`
APP_BAK="/data/backup/app/tomcat"
bak_file="tomcat_${DATE}.tar.Z"

if [ ! -s "${APP_BAK}/${bak_file}" ] ; then
echo "${APP_BAK}/${bak_file} not exsit ..."
echo "Start backup Tomcat to ${APP_BAK}/"
cd /app/
echo "tar tomcat directory ..."
tar cvf ${APP_BAK}/tomcat_${DATE}.tar ./tomcat/ --exclude 'logs' --exclude 'catalina.out' && echo "${APP_BAK}/tomcat_${DATE}.tar is ok ..."
cd ${APP_BAK}/
rm -rf ./tomcat_${DATE}.tar.Z
echo "compress tomcat tar ..."
echo ""
compress tomcat_${DATE}.tar && echo "tomcat_${DATE}.tar.Z is ok"
else
echo "${APP_BAK}/${bak_file} is exsit ..."
echo "exit backup script ..."
fi

################### cat app_log.sh
#!/bin/sh
DATE=`date +%w`
APP_BAK="/data/backup/logs/tomcat"
bak_file="tomcat_log_${DATE}.tar.Z"

if [ ! -s "${APP_BAK}/${bak_file}" ] ; then
echo "${APP_BAK}/${bak_file} not exsit ..."
echo "Start backup Tomcat to ${APP_BAK}/"
cd /app/
echo "tar tomcat logs directory ..."
echo ""
tar cvf ${APP_BAK}/tomcat_log_${DATE}.tar ./tomcat/logs/ && echo "tomcat logs tar is ok ..."
cd ${APP_BAK}/
rm -rf ./tomcat_log_${DATE}.tar.Z
echo "compress tomcat logs tar ..."
echo ""
compress tomcat_log_${DATE}.tar && echo "compress tomcat logs is ok ..."
echo ""
echo ""
echo "Clear Tomcat logs/catalina.out ..."
cd /app/tomcat/logs/
# tail -50000 catalina.out >catalina.out_50000 && >./catalina.out
# rm -rf localhost*.txt
else
echo "${APP_BAK}/${bak_file} is exsit ..."
echo "exit backup script ..."
fi

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8806316/viewspace-1017159/,如需轉載,請註明出處,否則將追究法律責任。