-
[root@localhost python]# more goo.sh
-
#!/bin/bash
-
# author:Jonnychen
-
# date:2014-7-19
-
# set -x
-
-
# get the key value of input
-
get_key_value()
-
{
-
echo "$1" | sed 's/^--[A-Za-z_-]*=//'
-
}
-
-
-
use_help() ----用法
-
{
-
cat << EOF
-
Info :
-
Author:Michael.xu
-
Usage :
-
Usage : $0 [configure-options]
-
-? , --help
-
--user=<> , set login user
-
--password=<> , set login user password
-
--port=<>,default 3306
-
--host=<>,default 127.0.0.1
-
-innodb , include (com_select,com_insert,com_update,com_delete)
-
-innodb_buffer_hit , innodb buffer pool hits
-
EOF
-
}
-
-
parse_options()
-
{
-
while [ $# -gt 0 ]
-
do
-
case "$1" in
-
--user=*)
-
LOGIN_USER=`get_key_value "$1"`;;
-
--password=*)
-
LOGIN_PASSWORD=`get_key_value "$1"`;;
-
--port=*)
-
LOGIN_PORT=`get_key_value "$1"`;;
-
--host=*)
-
LOGIN_HOST=`get_key_value "$1"`;;
-
-? | --help)
-
use_help
-
exit 0;;
-
*)
-
echo "unknown configure option '$1'"
-
exit 1;;
-
esac
-
shift
-
done
-
}
-
LOGIN_USER=root ---默认值
LOGIN_PORT=3306 ---默认值
LOGIN_HOST=127.0.0.1 ---默认值
-
-
parse_options "$@"
echo "$LOGIN_USER $LOGIN_PASSWORD $LOGIN_PORT $LOGIN_HOST"
-
if [ ! -n "$LOGIN_USER" ];then
-
use_help
-
exit
-
fi
-
-
-
if [ ! -n "$LOGIN_PASSWORD" ];then
-
use_help
-
exit
-
fi
-
-
-
-
-
mysql -u$LOGIN_USER -p$LOGIN_PASSWORD -P$LOGIN_PORT -h$LOGIN_HOST -e "select now()"