sysbench scripts (7)
来源:互联网 发布:伊芙蕾雅4p真假知乎 编辑:程序博客网 时间:2024/06/14 04:18
衔接上文,以下是test文件夹下的脚本。
7、sysbench_oltp.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. --sysbenchdir=<> Set the sysbench directory --host=<> Set the host name. --port=<> Set the port number. --database=<> Set the database to sysbench. --user=<> Set the user name. --password=<> Set the password. --socket=<> Set the socket file --tablesize=<> Set the table seize. --engine=<> Set the sysbench engine. --threads=<> Set the threads number. --max-requests=<> Set the max request numbers. --max-time=<> Set the max run time. --var=<> Set the variable. --value=<> Set the value of the variable. -p,--prepare Set the prepare procedure. -r,--run Set the run procedure. -c,--cleanup Set the cleanup procedure. --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: sysbenchdir $SYSBENCHDIR host $HOST port $PORT database $DATABASE user $USER password $PASSWORD socket $SOCKET tablesize $TABLESIZE engine $ENGINE threads $THREADS max-requests $REQUESTS max-time $TIME var $VAR value $VALUE prepare FALSE run TRUE cleanup FALSE outputdir $OUTPUTDIREOF}# Parse the input arguments and get the value of the input argument.parse_options(){ while test $# -gt 0 do case "$1" in --sysbenchdir=*) SYSBENCHDIR=`get_key_value "$1"`;; --host=*) HOST=`get_key_value "$1"`;; --port=*) PORT=`get_key_value "$1"`;; --database=*) DATABASE=`get_key_value "$1"`;; --user=*) USER=`get_key_value "$1"`;; --password=*) PASSWORD=`get_key_value "$1"`;; --socket=*) SOCKET=`get_key_value "$1"`;; --tablesize=*) TABLESIZE=`get_key_value "$1"`;; --engine=*) ENGINE=`get_key_value "$1"`;; --threads=*) THREADS=`get_key_value "$1"`;; --max-requests=*) REQUESTS=`get_key_value "$1"`;; --max-time=*) TIME=`get_key_value "$1"`;; --var=*) VAR=`get_key_value "$1"`;; --value=*) VALUE=`get_key_value "$1"`;; -p | --prepare) PREPARE=1;; -r | --run) RUN=1;; -c | --cleanup) CLEANUP=1;; --outputdir=*) OUTPUTDIR=`get_key_value "$1"`;; -? | --help) usage print_default exit 0;; *) echo "Unknown option '$1'" exit 1;; esac shift done}# Sysbench prepare procedure, that generated the test data and sysbench environment. prepare(){ $SYSBENCH --test=oltp --mysql-host=$HOST --mysql-port=$PORT --mysql-user=$USER \ --mysql-password=$PASSWORD --mysql-socket=$SOCKET --mysql-db=$DATABASE \ --mysql-table-engine=$ENGINE --oltp-table-size=$TABLESIZE prepare if [ $? -ne 0 ] then echo "Exit with error when prepare procedure!" exit -1 fi}# Sysbench run procedure, that test the mysql server with the given argments.run(){ $SYSBENCH --test=oltp --mysql-host=$HOST --mysql-port=$PORT --mysql-user=$USER \ --mysql-password=$PASSWORD --mysql-socket=$SOCKET --mysql-db=$DATABASE \ --mysql-table-engine=$ENGINE --oltp-table-size=$TABLESIZE --num-threads=$THREADS \ --max-requests=$REQUESTS --max-time=$TIME run if [ $? -ne 0 ] then echo "Exit with error when run procedure!" exit -1 fi}# Sysbench cleanup procedure, that cleanup the environment of sysbench test.cleanup(){ $SYSBENCH --test=oltp --mysql-host=$HOST --mysql-port=$PORT --mysql-user=$USER \ --mysql-password=$PASSWORD --mysql-socket=$SOCKET --mysql-db=$DATABASE \ --mysql-table-engine=$ENGINE cleanup}############################################################## Define the variables the script used for executing.SYSBENCHDIR=/opt/sysbenchHOST=localhostPORT=3306DATABASE=testUSER=rootPASSWORD=SOCKET=/tmp/mysql.sockTABLESIZE=10000ENGINE=innodbTHREADS=1REQUEST=10000TIME=1000VAR="full"VALUE="default"PREPARE=0CLEANUP=0RUN=0OUTPUTDIR=/opt/output# Call the parse_options function to parse the input arguments.parse_options "$@"# Define the sysbench executable program.SYSBENCH=$SYSBENCHDIR/bin/sysbench# If the mysql and sysbench executable program is not exist, exit the script.# Or, run the sysbench test.if [ -f $SYSBENCH ]then # If the output directory is not exist, then make directory. [[ -d $OUTPUTDIR ]] || mkdir -p $OUTPUTDIR # Print the current value of the script arguments. print_default | tee ${OUTPUTDIR}/sysbench_${VAR}_${VALUE}_thread_${THREADS}.cnf if [ $PREPARE -ne 1 ] && [ $RUN -ne 1 ] && [ $CLEANUP -ne 1 ] then echo "Please be ensure you operation for sysbench test,the operations are" echo "[--prepare| --run| --cleanup]." exit 1 fi if [ $PREPARE -eq 1 ] then # Cleanup the environment and the test data of the sysbench. cleanup # Prepare the environment and the test data for sysbench. prepare fi if [ $RUN -eq 1 ] then # Running the sysbench test. run | tee ${OUTPUTDIR}/sysbench_${VAR}_${VALUE}_thread_${THREADS}.res fi if [ $CLEANUP -eq 1 ] then # Cleanup the environment and the test data of the sysbench. cleanup fi else echo "$SYSBENCH is not exist!" echo "Please check the sysbench home directory." exit -1 fiecho "The test is successfully finished!"echo "----------------------------------"exit 0
- sysbench scripts (7)
- Sysbench scripts使用说明文档
- Sysbench scripts源码分析
- sysbench scripts (1)
- sysbench scripts (2)
- sysbench scripts (3)
- sysbench scripts (4)
- sysbench scripts (5)
- sysbench scripts (6)
- sysbench scripts (8)
- sysbench scripts (9)
- sysbench scripts (10)
- sysbench scripts (11)
- sysbench scripts (12)
- sysbench scripts (13)
- sysbench scripts (14)
- sysbench scripts (15)
- sysbench
- sprintf函数的用法
- jQuery 动态内容添,获取HTML标签和属性
- sysbench scripts (6)
- SQL Server 2008 变量叠加必须初始化
- 【已解决】可执行程序无法在Linux上运行,显示line 1: syntax error: word unexpected (expecting ")
- sysbench scripts (7)
- free
- 中文编码杂谈
- sysbench scripts (8)
- 使用ibatis抛出java.lang.IllegalArgumentException实则抛出:NestedSQLException异常
- sysbench scripts (9)
- ADT18 编译低版本项目遇到的问题
- SQL语句取得最大件数(MSSQL ORACLE Postgre,top rownum,limit)
- lua c在linux下的编译