sysbench scripts (4)

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

    4、innodb_stat.sh脚本

#! /bin/sh

###########################################################
# Copyright (c) 2012, Heng.Wang. All rights reserved.
#
# This program is used to collect the engine innodb status of 
# mysql server with a given interval time.
###########################################################

# 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 <<EOF
Usage: $0 [configure-options]
  -?, --help                       Show this help message.
  --mysqldir=<>                    Set the mysql directory  
  --host=<>                        Set the host name.
  --port=<>                        Set the port number.
  --user=<>                        Set the user name.
  --password=<>                    Set the password.
  --socket=<>                      Set the socket file  
  --interval=<>                    Set the interval time to show the engine innodb status
  --outputdir=<>                   Set the output directory.  

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
  host              $HOST
  port              $PORT
  user              $USER
  password          $PASSWORD
  socket            $SOCKET
  interval          $INTERVAL
  outputdir         $OUTPUTDIR

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"`;;
    --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"`;;
    --interval=*)
      INTERVAL=`get_key_value "$1"`;;
    --outputdir=*)
      OUTPUTDIR=`get_key_value "$1"`;;
    -? | --help)
      usage
      exit 0;;
    *)
      echo "Unknown option '$1'"
      exit 1;;
    esac
    shift
  done
}

#############################################################
# Define the variables the script used for executing.
MYSQLDIR=/opt/Percona-Server
HOST=localhost
PORT=3306
USER=root
PASSWORD=
SOCKET=/tmp/mysql.sock
INTERVAL=1
OUTPUTDIR=/opt/output/

# Call the parse_options function to parse the input arguments.
parse_options "$@"

# Define the mysql and sysbench executable program.
MYSQL=$MYSQLDIR/bin/mysql

# If the mysql is not exist, exit the script.
if [ -f $MYSQL ]
then
  # If the output directory is not exist, then make directory.
  [[ -d $OUTPUTDIR ]] || mkdir -p $OUTPUTDIR

## The MySQL will exit while the lsn never vary within the 10 times.
# Record the innodb engine status all the time.
  while true
  do    
    $MYSQL --host=$HOST --port=$PORT --user=$USER --password=$PASSWORD --socket=$SOCKET -e "SHOW ENGINE INNODB STATUS\G" >> ${OUTPUTDIR}/innodb_stat_interval_${INTERVAL}_${HOST}_${PORT}.stat
    sleep $INTERVAL
  done

else  
  echo "$MYSQL is not exist!"
  echo "Please check the mysql home directory."
  exit -1
 
fi


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值