sysbench scripts (6)

来源:互联网 发布:搜索优化翻译 编辑:程序博客网 时间:2024/06/07 03:09

    衔接上文,以下是test文件夹下的脚本。

    6、server_op.sh脚本

#! /bin/sh############################################################ Copyright (c) 2012, Heng.Wang. All rights reserved.## This program is benifit for sysbench oltp test.############################################################ set -x# Get the key value of input arguments format like '--args=value'.get_key_value(){    echo "$1" | sed 's/^--[a-zA-Z_-]*=//'     }# Usage will be helpful when you need to input the valid arguments.usage(){cat <<EOFUsage: $0 [configure-options]  -?, --help                       Show this help message.  --mysqldir=<>                    Set the mysql directory  --defaults-file=<>               Set the configure file for mysql  --host=<>                        Set the host name.  --port=<>                        Set the port number.  --user=<>                        Set the user name.  --password=<>                    Set the password.  --socket=<>                      Set the socket file.  -s,--start                       Start the mysql server.  -d,--shutdown                    Shutdown the mysql server.  Note: this script is intended for internal use by developers.EOF}# Print the default value of the arguments of the script.print_default(){cat <<EOF  The default value of the variables:    mysqldir          $MYSQLDIR  defaults-file    $CONFIG  host              $HOST  port              $PORT  user              $USER  password          $PASSWORD  socket            $SOCKET  start             FALSE  shutdown          FALSE  EOF}# Parse the input arguments and get the value of the input argument.parse_options(){  while test $# -gt 0  do    case "$1" in        --mysqldir=*)      MYSQLDIR=`get_key_value "$1"`;;    --defaults-file=*)      CONFIG=`get_key_value "$1"`;;    --host=*)      HOST=`get_key_value "$1"`;;    --port=*)      PORT=`get_key_value "$1"`;;    --user=*)      USER=`get_key_value "$1"`;;    --password=*)      PASSWORD=`get_key_value "$1"`;;    --socket=*)      SOCKET=`get_key_value "$1"`;;    -s | --start)      START=1;;    -d | --shutdown)      SHUTDOWN=1;;    -? | --help)      usage      print_default      exit 0;;    *)      echo "Unknown option '$1'"      exit 1;;    esac    shift  done}#Shutdown the mysql server after the sysbench test.shutdown_mysqld(){  cd $MYSQLDIR  ./bin/mysqladmin --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD --socket=$SOCKET shutdown > /dev/null  if [ $? -ne 0 ]  then    echo "Exit with error when shutdown the mysql server procedure!"    exit -1  fi  sleep 10}#Start the mysql server if the server is not running.start_mysqld(){  cd $MYSQLDIR  ./bin/mysqladmin  --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD --socket=$SOCKET status > /dev/null  if [ $? -ne 0 ]  then    ./bin/mysqld_safe --defaults-file=$CONFIG > /dev/null &    if [ $? -ne 0 ]    then      echo "Exit with error when start the mysql server procedure!"      exit -1    fi    sleep 30  fi}############################################################## Define the variables the script used for executing.MYSQLDIR=/opt/Percona-ServerCONFIG=/opt/Percona-Server/etc/my.cnfHOST=localhostPORT=3306USER=rootPASSWORD=SOCKET=/tmp/mysql.sockSTART=0SHUTDOWN=0# Call the parse_options function to parse the input arguments.parse_options "$@"if [ $START -eq 0 ] &&  [ $SHUTDOWN -eq 0 ]then  echo "Please be ensure you operation for mysql server."  exit 1fiif [ $START -eq 1  ]then  #Start the mysql server  start_mysqld  echo "The server is successfully started!"fi if [ $SHUTDOWN -eq 1 ]then  #Shutdown the mysql server  shutdown_mysqld  echo "The server is successfully shutdown!"fiexit 0


原创粉丝点击