标签:war .gz x86_64 case echo files chm tar.gz chmod
#!/bin/bash
#create by steven
#create date 2017/04/07
###########define variable
. /etc/init.d/functions
version="mysql-5.5.54-linux2.6-x86_64" #mysql software version
install_path=/application/mysql-5.5.54 #mysql install path
password="123456" #defualt mysql root password
resource=/software #mysql tar file
linkdir=/application/mysql #mysql link folder
datadir=/application/mysql/data #mysql data file folder
#####function
function menu(){
echo ‘
====MySQL Auto install====
1.Prepare to install mysql
==========================
2.Install MySQL
==========================
3 Start MySQL
==========================
4.Stop MySQL
==========================
5. Exit
==========================
‘‘‘
read -t 10 -p "Pls input the number what you want:" num
}
pre_install(){
mkdir -p "$datadir"
cd $resource
tar -xf "$version.tar.gz"
ln -s $install_path $linkdir
cd $resource/$version
mv * $linkdir/
useradd mysql -s /sbin/nologin -M >>/tmp/mysql_install_log
echo "$password"|passwd --stdin mysql >>/tmp/mysql_install_log
chown -R mysql.mysql "$linkdir"
}
install(){
"$linkdir"/scripts/mysql_install_db --basedir=$linkdir --datadir=$datadir --user=mysql &>/dev/null
cp $linkdir/support-files/mysql.server /etc/init.d/mysqld
cp $linkdir/support-files/my-small.cnf /etc/my.cnf
chmod +x /etc/init.d/mysqld
/bin/sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
}
start(){
/etc/init.d/mysqld start
}
stop(){
/etc/init.d/mysqld stop
}
exit(){
exit 0
}
main(){
menu
case $num in
1)
pre_install
if [ $? -eq 0 ]
then
echo "pre_install succceed"
else
echo "pre_install failed"
fi
;;
2)
install
if [ $? -eq 0 ]
then
echo "install succceed"
else
echo "install failed"
fi
;;
3)
echo "This action need few seconds"
start
if [ $? -eq 0 ]
then
echo "MySQL start succceed"
else
echo "MYSQL start failed"
fi
;;
4)
stop
if [ $? -eq 0 ]
then
echo "MySQL stop succceed"
else
echo "MySQL stop failed"
fi
;;
5)
echo "you will be out in 2 seconds"
sleep 2
exit 0
;;
*)
[ "$num" -ne "1" -o "$num" -ne "2" -o "$num" -ne "3" -o "$num" -ne "4" -o "$num" -ne "5" ]&&echo "Usage should be $0:{1|2|3|4|5}"
esac
}
########Begin execute
while true
do
main $1
done
标签:war .gz x86_64 case echo files chm tar.gz chmod
原文地址:http://www.cnblogs.com/dianzixiaoming/p/6692582.html