tomcat重启脚本

#!/bin/bash
RED=’\E[1;31m’
GRN=’\E[1;32m’
RES=’\E[0m’
tomcat_name=”tomcat-guanli”
tomcat_log=”/project/opt/${tomcat_name}/logs/catalina.out”
tomcat_start=”/project/opt/${tomcat_name}/bin/startup.sh”
tomcat_pid=`ps aux | grep ${tomcat_name} | grep -v grep | awk ‘{print $2}’`
if [ ! ${tomcat_pid} ];then
echo -e “${RED}tomcat not start…${RES}”
echo -e “${RED}please start tomcat…${RES}”
echo -e “${GRN}start ${tomcat_name}now…${RES}”
sleep 1
sh $tomcat_start ; tail -f $tomcat_log
else
echo -e “${GRN}tomcat pid is ${tomcat_pid} ${RES}”
echo -e “${RED}kill ${tomcat_name}…${RES}”
kill -9 $tomcat_pid
sleep 1
echo -e “${GRN}start ${tomcat_name}…${RES}”
sh $tomcat_start ;tail -f $tomcat_log
fi

mysql5.6自动化安装脚本

大家在使用的时候需要根据实际情况来调整路径变量

#!/bin/bash

#制作人:张阳
#时间:2016/2/25 14:25

#定义颜色变量
RED_COLOR=’\E[1;31m’ #红
GREEN_COLOR=’\E[1;32m’ #绿
YELOW_COLOR=’\E[1;33m’ #黄
BLUE_COLOR=’\E[1;34m’ #蓝
PINK=’\E[1;35m’ #粉红
RES=’\E[0m’

#定义脚本内部变量
SOFT_DIR=/soft
MYSQL_NAME=”mysql-5.6.29.tar.gz”
USER=`cat /etc/passwd | grep ^mysql | wc -l`
MYSQL_INSTALL_DIR=/usr/local/mysql
MY_CNF=`ls /etc/my.cnf |wc -l`
SRC=”/usr/src”

check_environment(){
yum install make gcc-c++ cmake bison-devel ncurses-devel -y

}

check_install(){
if [ -d $SOFT_DIR ];then
cd $SOFT_DIR
if [ -f $MYSQL_NAME ];then
tar xf $MYSQL_NAME -C $SRC
cd $SRC/mysql-5.6.29
cmake \
-DCMAKE_INSTALL_PREFIX=$MYSQL_INSTALL_DIR \
-DMYSQL_DATADIR=$MYSQL_INSTALL_DIR/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
if [ $? -eq 0 ];then
make
if [ $? -eq 0 ];then
make install
if [ $? -eq 0 ];then
echo -e “$GREEN_COLOR 软件已安装完成 $RES”

else
echo -e “$RED_COLOR make install error $RES”
exit 1
fi
else
echo -e “$RED_COLOR make error $RES”
exit 1
fi
else
echo -e “$RED_COLOR configure error $RES”
exit 1
fi
else
echo -e “$RED_COLOR 没有文件,请检查文件或文件名是否正确 $RES”
exit 1
fi
else
echo -e “$RED_COLOR 没有目录 $RES”
exit 1
fi
}

check_user(){
if [ $USER -eq 1 ];then
useradd -g mysql -s /sbin/nologin mysql
else
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
fi
}

check_perm(){
chown -R mysql.mysql $MYSQL_INSTALL_DIR
}

mysql_configure(){
cd $MYSQL_INSTALL_DIR
scripts/mysql_install_db –basedir=$MYSQL_INSTALL_DIR –datadir=$MYSQL_INSTALL_DIR/data –user=mysql
}

mysql_init(){
cp $MYSQL_INSTALL_DIR/support-files/mysql.server /etc/init.d/mysql
if [ $MY_CNF -eq 0 ];then
cp $MYSQL_INSTALL_DIR/my.cnf /etc/my.cnf
else
rm -rf /etc/my.cnf
cp $MYSQL_INSTALL_DIR/my.cnf /etc/my.cnf
fi
chkconfig mysql on
/etc/init.d/mysql start
if [ $? -eq 0 ];then
echo -e “$GREEN_COLOR mysql安装完成 $RES”
else
echo -e “$RED_COLOR mysql 安装失败,请检查原因 $RES”
fi
}

check_path(){
cat >>/etc/profile <<EOF
export PATH=/usr/local/mysql/bin:$PATH
export PATH=/usr/local/mysql/sbin:$PATH
EOF
sleep 1
source /etc/profile
}

main(){
check_environment
check_install
check_user
check_perm
mysql_configure
mysql_init
check_path
}

echo -ne “$GREEN_COLOR 在安装之前确认是否有${SOFT_DIR}这个目录,是否开始安装:Y/N $RES”

read A

case $A in
Y)
main;;
N)
echo -e “$RED_COLOR 退出安装 $RES”
break;;
*)
echo -e “$RED_COLOR 非法输入,请输入大写的Y/N $RES”
break
esac