用shell脚本写的一个交互式linux命令行工具
#!/bin/bash################ 宏定义 ##########################WORKDIR=$(pwd)LOG_FILE=${WORKDIR}/sfs_serv_tool.logTMP_SQL_TABLE_FILE="./tmp_clean_table.sql"DB_NAME_PREFIX="dfs_proxy_db_
·
#!/bin/bash
################ 宏定义 ##########################
WORKDIR=$(pwd)
LOG_FILE=${WORKDIR}/sfs_serv_tool.log
TMP_SQL_TABLE_FILE="./tmp_clean_table.sql"
DB_NAME_PREFIX="dfs_proxy_db_"
INDEX_EXE=${WORKDIR}/table_index
MYSQL=mysql
DB_NUM=10
DB_HOST=""
DB_USER=""
DB_PASS=""
DB_NAME=""
SERV_ID_LABEL="SERVICE ID :"
SERV_PASS_LABEL="SERVICE PASSWD:"
SERV_TYPE_LABEL="SERVICE TYPE :"
OWNER_ID_LABEL="OWNER ID :"
RW_FLAG_LABEL="RW FLAG :"
ALL_SIZE_LABEL="ALLOC SIZE :"
USE_SIZE_LABEL="USE SIZE :"
SERV_ID=""
SERV_PASS=""
SERV_TYPE=""
OWNER_ID=""
RW_FLAG=""
ALL_SIZE=""
USE_SIZE=""
ERR_INFO=""
################ 日志输出处理函数 ##################
Log()
{
DATE=`date '+%Y %T'`
# echo $*
if [ "-$1" == "-1" ]; then
echo "${DATE} INFO: $2">>${LOG_FILE}
elif [ "-$1" == "-2" ];then
echo "${DATE} ERROR: $2">>${LOG_FILE}
else
echo "${DATE} Log argument type $1 illegal;">>${LOG_FILE}
echo "${DATE} ERROR: $2">>${LOG_FILE}
fi
}
################ 数字校验处理函数 ##################
AllocSizeInputCheck()
{
if [ $# -ne 1 ];then
return 1
fi
test_string=$1
if [ "-${test_string}" = "-" ]; then
return 1
fi
temp_string=""
temp_string=`expr ${test_string} + 0` >/dev/null 2>&1
if [ "-${temp_string}" = "-" ]; then
return 1
fi
if [ ${test_string} -le 0 ];then
return 1
fi
return 0
}
################ 重置数据处理函数 ##################
ResetData()
{
SERV_ID=""
SERV_PASS=""
SERV_TYPE=""
OWNER_ID=""
RW_FLAG=""
ALL_SIZE=""
USE_SIZE=""
return 0
}
################ 数据库操作处理函数 ##################
Mysql_op()
{
DB_NAME=$1
sql_express=$2
mysql -h${DB_HOST} -D ${DB_NAME} -u${DB_USER} -p${DB_PASS} << EOF
use ${DB_NAME};
${sql_express};
QUIT
EOF
}
################ 插入用户数据处理函数 ##################
InsertUserData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="INSERT INTO SERVICE_INFO_${TABLE_INDEX}(service_id, service_pwd, service_type, owner_id, rw_flag, use_size, all_size)"
SQL="${SQL} VALUES ('${1}', '${2}', '${3}', '${4}', ${5}, 0, ${6})"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Insert service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 查询表数据处理函数 ##################
QueryServData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="SELECT service_id, service_pwd, service_type, owner_id, rw_flag, use_size, all_size FROM SERVICE_INFO_${TABLE_INDEX} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Query service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
if [ -n "${SQL_RESULT}" ];then
SERV_ID=`echo ${SQL_RESULT} | grep "service_id" | awk '{print $8}'`
SERV_PASS=`echo ${SQL_RESULT} | grep "service_pwd" | awk '{print $9}'`
SERV_TYPE=`echo ${SQL_RESULT} | grep "service_type" | awk '{print $10}'`
OWNER_ID=`echo ${SQL_RESULT} | grep "owner_id" | awk '{print $11}'`
RW_FLAG=`echo ${SQL_RESULT} | grep "rw_flag" | awk '{print $12}'`
USE_SIZE=`echo ${SQL_RESULT} | grep "use_size" | awk '{print $13}'`
ALL_SIZE=`echo ${SQL_RESULT} | grep "all_size" | awk '{print $14}'`
fi
echo "--- $? ----"
echo ${SQL_RESULT}
echo ""
if [ "-${SERV_ID}" == "-" ];then
return 1
fi
return 0
}
################ 删除业务表数据处理函数 ##################
DeleteUserData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="DELETE FROM SERVICE_INFO_${TABLE_INDEX} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Delete service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 业务用户增加存储空间处理函数 ##################
AddStoreSize()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="UPDATE SERVICE_INFO_${TABLE_INDEX} SET all_size=all_size+${2} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Update service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 新增用户菜单函数 #########################
AddUserMenu()
{
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools add"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID} "
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
SERV_ID=${_input}
PROC_STAGE=2
PROMPT="Please enter SERVICE PASSWD"
fi
continue
;;
2)
if [ "-${_input}" != "-" ];then
SERV_PASS=${_input}
PROC_STAGE=3
PROMPT="Please enter SERVICE TYPE [1-2]"
fi
continue
;;
3)
if [ "-${_input}" == "-1" ] || [ "-${_input}" == "-2" ];then
SERV_TYPE=${_input}
PROC_STAGE=4
PROMPT="Please enter OWNER ID"
else
ERR_INFO="input SERVICE TYPE [${_input}] illegal"
fi
continue
;;
4)
if [ "-${_input}" != "-" ];then
OWNER_ID=${_input}
PROC_STAGE=5
PROMPT="Please enter RW FLAG [1-2]"
fi
continue
;;
5)
if [ "-${_input}" == "-1" ] || [ "-${_input}" == "-2" ];then
RW_FLAG=${_input}
PROC_STAGE=6
PROMPT="Please enter ALLOC SIZE"
else
ERR_INFO="input RW_FLAG [${_input}] illegal"
fi
continue
;;
6)
if [ "-${_input}" != "-" ];then
AllocSizeInputCheck ${_input}
if [ $? -ne 0 ];then
ERR_INFO="input ALLOC SIZE [${_input}] illegal"
continue
fi
ALL_SIZE=${_input}
PROC_STAGE=9
PROMPT="Do you confirm add new user [y/n]"
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
InsertUserData "${SERV_ID}" "${SERV_PASS}" "${SERV_TYPE}" "${OWNER_ID}" "${RW_FLAG}" "${ALL_SIZE}"
if [ $? -ne 0 ];then
ERR_INFO="add service [${SERV_ID}] failed"
else
ERR_INFO="add service [${SERV_ID}] success"
fi
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
ResetData
continue
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
ResetData
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################### 查询用户菜单函数 #########################
QueryUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools query"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
fi
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 修改用户菜单函数 #########################
ModifyUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
_input=""
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools modify"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
else
SERV_ID=${_input}
PROC_STAGE=2
PROMPT="Please enter ADD SIZE(unit: M)"
fi
fi
continue
;;
2)
if [ "-${_input}" != "-" ];then
AllocSizeInputCheck ${_input}
if [ $? -ne 0 ];then
ERR_INFO="input illegal [${_input}]"
continue
else
ALL_SIZE=${_input}
PROC_STAGE=9
PROMPT="Do you confirm add store size ${_input} M [y/n]"
fi
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
AddStoreSize "${SERV_ID}" "${ALL_SIZE}"
if [ $? -ne 0 ];then
ERR_INFO="service [${SERV_ID}] add store size [${ALL_SIZE}] failed."
else
ERR_INFO="service [${SERV_ID}] add store size [${ALL_SIZE}] success."
fi
ResetData
PROMPT="Please enter SERVICE ID"
PROC_STAGE=1
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
PROC_STAGE=1
ResetData
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 删除用户菜单函数 #########################
DeleteUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
_input=""
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools delete"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
else
PROC_STAGE=9
PROMPT="Do you confirm delete service user [y/n]"
fi
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
DeleteUserData "${SERV_ID}"
if [ $? -ne 0 ];then
ERR_INFO="delete [${SERV_ID}] failed."
else
ERR_INFO="delete [${SERV_ID}] success."
fi
ResetData
PROMPT="Please enter SERVICE ID"
PROC_STAGE=1
continue
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
PROC_STAGE=1
ResetData
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 主菜单函数 #########################
MainMenu()
{
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools"" ""main menu"
echo " _____________________________________________________________________________________"
echo " ||----1----Add user "
echo " ||----2----Query user "
echo " ||----3----Modify user "
echo " ||----4----Delete user "
echo " ||----0----Exit"
echo " ______________________________________________________________________________________"
echo -n " Please select [0-4]:"
read _input
case $_input in
1)
AddUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
2)
QueryUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
3)
ModifyUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
4)
DeleteUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
0)
INSTALLFLAG=0
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 提示处理函数 #####################
usage()
{
echo " usage"
echo " $0 <db_host_ip> <db_user_name> <db_pass_word>"
return 0;
}
################ 主处理函数 #####################
Process()
{
DB_HOST=${1}
DB_USER=${2}
DB_PASS=${3}
#DB_NAME="${DATABASE_NAME_PREFIX}7"
MainMenu
#QueryServData
if [ $? -ne 0 ]; then
Log 2 "Clean table data error."
return 1
fi
return 0
}
################ 主函数 #########################
Main()
{
if [ $# -ne 3 ];then
Log 2 "Input illegal: $*"
usage $*
return 1
fi
Process $*
return 0
}
Main $*
################ 宏定义 ##########################
WORKDIR=$(pwd)
LOG_FILE=${WORKDIR}/sfs_serv_tool.log
TMP_SQL_TABLE_FILE="./tmp_clean_table.sql"
DB_NAME_PREFIX="dfs_proxy_db_"
INDEX_EXE=${WORKDIR}/table_index
MYSQL=mysql
DB_NUM=10
DB_HOST=""
DB_USER=""
DB_PASS=""
DB_NAME=""
SERV_ID_LABEL="SERVICE ID :"
SERV_PASS_LABEL="SERVICE PASSWD:"
SERV_TYPE_LABEL="SERVICE TYPE :"
OWNER_ID_LABEL="OWNER ID :"
RW_FLAG_LABEL="RW FLAG :"
ALL_SIZE_LABEL="ALLOC SIZE :"
USE_SIZE_LABEL="USE SIZE :"
SERV_ID=""
SERV_PASS=""
SERV_TYPE=""
OWNER_ID=""
RW_FLAG=""
ALL_SIZE=""
USE_SIZE=""
ERR_INFO=""
################ 日志输出处理函数 ##################
Log()
{
DATE=`date '+%Y %T'`
# echo $*
if [ "-$1" == "-1" ]; then
echo "${DATE} INFO: $2">>${LOG_FILE}
elif [ "-$1" == "-2" ];then
echo "${DATE} ERROR: $2">>${LOG_FILE}
else
echo "${DATE} Log argument type $1 illegal;">>${LOG_FILE}
echo "${DATE} ERROR: $2">>${LOG_FILE}
fi
}
################ 数字校验处理函数 ##################
AllocSizeInputCheck()
{
if [ $# -ne 1 ];then
return 1
fi
test_string=$1
if [ "-${test_string}" = "-" ]; then
return 1
fi
temp_string=""
temp_string=`expr ${test_string} + 0` >/dev/null 2>&1
if [ "-${temp_string}" = "-" ]; then
return 1
fi
if [ ${test_string} -le 0 ];then
return 1
fi
return 0
}
################ 重置数据处理函数 ##################
ResetData()
{
SERV_ID=""
SERV_PASS=""
SERV_TYPE=""
OWNER_ID=""
RW_FLAG=""
ALL_SIZE=""
USE_SIZE=""
return 0
}
################ 数据库操作处理函数 ##################
Mysql_op()
{
DB_NAME=$1
sql_express=$2
mysql -h${DB_HOST} -D ${DB_NAME} -u${DB_USER} -p${DB_PASS} << EOF
use ${DB_NAME};
${sql_express};
QUIT
EOF
}
################ 插入用户数据处理函数 ##################
InsertUserData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="INSERT INTO SERVICE_INFO_${TABLE_INDEX}(service_id, service_pwd, service_type, owner_id, rw_flag, use_size, all_size)"
SQL="${SQL} VALUES ('${1}', '${2}', '${3}', '${4}', ${5}, 0, ${6})"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Insert service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 查询表数据处理函数 ##################
QueryServData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="SELECT service_id, service_pwd, service_type, owner_id, rw_flag, use_size, all_size FROM SERVICE_INFO_${TABLE_INDEX} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Query service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
if [ -n "${SQL_RESULT}" ];then
SERV_ID=`echo ${SQL_RESULT} | grep "service_id" | awk '{print $8}'`
SERV_PASS=`echo ${SQL_RESULT} | grep "service_pwd" | awk '{print $9}'`
SERV_TYPE=`echo ${SQL_RESULT} | grep "service_type" | awk '{print $10}'`
OWNER_ID=`echo ${SQL_RESULT} | grep "owner_id" | awk '{print $11}'`
RW_FLAG=`echo ${SQL_RESULT} | grep "rw_flag" | awk '{print $12}'`
USE_SIZE=`echo ${SQL_RESULT} | grep "use_size" | awk '{print $13}'`
ALL_SIZE=`echo ${SQL_RESULT} | grep "all_size" | awk '{print $14}'`
fi
echo "--- $? ----"
echo ${SQL_RESULT}
echo ""
if [ "-${SERV_ID}" == "-" ];then
return 1
fi
return 0
}
################ 删除业务表数据处理函数 ##################
DeleteUserData()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="DELETE FROM SERVICE_INFO_${TABLE_INDEX} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Delete service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 业务用户增加存储空间处理函数 ##################
AddStoreSize()
{
INDEX_RESULT=`${INDEX_EXE} ${1}`
DB_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $4}'`
TABLE_INDEX=`echo ${INDEX_RESULT} | awk -F: '{print $6}'`
SQL="UPDATE SERVICE_INFO_${TABLE_INDEX} SET all_size=all_size+${2} WHERE service_id='${1}'"
Log 1 "DB_INDEX:${DB_INDEX}, ${SQL}"
SQL_RESULT=`Mysql_op "${DB_NAME_PREFIX}${DB_INDEX}" "${SQL}"`
if [ $? -ne 0 ];then
Log 2 "Update service user:${1} error, SQL_RESULT:${SQL_RESULT}, SQL:${SQL}"
return 1
fi
return 0
}
################ 新增用户菜单函数 #########################
AddUserMenu()
{
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools add"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID} "
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
SERV_ID=${_input}
PROC_STAGE=2
PROMPT="Please enter SERVICE PASSWD"
fi
continue
;;
2)
if [ "-${_input}" != "-" ];then
SERV_PASS=${_input}
PROC_STAGE=3
PROMPT="Please enter SERVICE TYPE [1-2]"
fi
continue
;;
3)
if [ "-${_input}" == "-1" ] || [ "-${_input}" == "-2" ];then
SERV_TYPE=${_input}
PROC_STAGE=4
PROMPT="Please enter OWNER ID"
else
ERR_INFO="input SERVICE TYPE [${_input}] illegal"
fi
continue
;;
4)
if [ "-${_input}" != "-" ];then
OWNER_ID=${_input}
PROC_STAGE=5
PROMPT="Please enter RW FLAG [1-2]"
fi
continue
;;
5)
if [ "-${_input}" == "-1" ] || [ "-${_input}" == "-2" ];then
RW_FLAG=${_input}
PROC_STAGE=6
PROMPT="Please enter ALLOC SIZE"
else
ERR_INFO="input RW_FLAG [${_input}] illegal"
fi
continue
;;
6)
if [ "-${_input}" != "-" ];then
AllocSizeInputCheck ${_input}
if [ $? -ne 0 ];then
ERR_INFO="input ALLOC SIZE [${_input}] illegal"
continue
fi
ALL_SIZE=${_input}
PROC_STAGE=9
PROMPT="Do you confirm add new user [y/n]"
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
InsertUserData "${SERV_ID}" "${SERV_PASS}" "${SERV_TYPE}" "${OWNER_ID}" "${RW_FLAG}" "${ALL_SIZE}"
if [ $? -ne 0 ];then
ERR_INFO="add service [${SERV_ID}] failed"
else
ERR_INFO="add service [${SERV_ID}] success"
fi
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
ResetData
continue
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
ResetData
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################### 查询用户菜单函数 #########################
QueryUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools query"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
fi
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 修改用户菜单函数 #########################
ModifyUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
_input=""
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools modify"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
else
SERV_ID=${_input}
PROC_STAGE=2
PROMPT="Please enter ADD SIZE(unit: M)"
fi
fi
continue
;;
2)
if [ "-${_input}" != "-" ];then
AllocSizeInputCheck ${_input}
if [ $? -ne 0 ];then
ERR_INFO="input illegal [${_input}]"
continue
else
ALL_SIZE=${_input}
PROC_STAGE=9
PROMPT="Do you confirm add store size ${_input} M [y/n]"
fi
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
AddStoreSize "${SERV_ID}" "${ALL_SIZE}"
if [ $? -ne 0 ];then
ERR_INFO="service [${SERV_ID}] add store size [${ALL_SIZE}] failed."
else
ERR_INFO="service [${SERV_ID}] add store size [${ALL_SIZE}] success."
fi
ResetData
PROMPT="Please enter SERVICE ID"
PROC_STAGE=1
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
PROC_STAGE=1
ResetData
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 删除用户菜单函数 #########################
DeleteUserMenu()
{
_input=""
PROC_STAGE=1
PROMPT="Please enter SERVICE ID"
while true
do
_input=""
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools delete"
echo " _____________________________________________________________________________________"
echo " NOTE: ${ERR_INFO}"
echo " _____________________________________________________________________________________"
echo " ${SERV_ID_LABEL} ${SERV_ID}"
echo " ${SERV_PASS_LABEL} ${SERV_PASS}"
echo " ${SERV_TYPE_LABEL} ${SERV_TYPE}"
echo " ${OWNER_ID_LABEL} ${OWNER_ID}"
echo " ${RW_FLAG_LABEL} ${RW_FLAG}"
echo " ${ALL_SIZE_LABEL} ${ALL_SIZE}"
echo " ${USE_SIZE_LABEL} ${USE_SIZE}"
echo " ______________________________________________________________________________________"
echo -n " ${PROMPT}:"
read _input
case ${PROC_STAGE} in
1)
if [ "-${_input}" != "-" ];then
ERR_INFO=""
ResetData
QueryServData "${_input}"
if [ $? -ne 0 ];then
ERR_INFO="service id [${_input}] not exists !"
else
PROC_STAGE=9
PROMPT="Do you confirm delete service user [y/n]"
fi
fi
continue
;;
9)
if [ "-${_input}" == "-y" ] || [ "-${_input}" == "-Y" ];then
DeleteUserData "${SERV_ID}"
if [ $? -ne 0 ];then
ERR_INFO="delete [${SERV_ID}] failed."
else
ERR_INFO="delete [${SERV_ID}] success."
fi
ResetData
PROMPT="Please enter SERVICE ID"
PROC_STAGE=1
continue
fi
if [ "-${_input}" == "-n" ] || [ "-${_input}" == "-N" ];then
PROC_STAGE=1
ResetData
PROMPT="Please enter SERVICE ID"
fi
continue
;;
0)
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 主菜单函数 #########################
MainMenu()
{
while true
do
clear
echo " "
echo " _____________________________________________________________________________________"
echo " [Title]: SFS service user operator tools"" ""main menu"
echo " _____________________________________________________________________________________"
echo " ||----1----Add user "
echo " ||----2----Query user "
echo " ||----3----Modify user "
echo " ||----4----Delete user "
echo " ||----0----Exit"
echo " ______________________________________________________________________________________"
echo -n " Please select [0-4]:"
read _input
case $_input in
1)
AddUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
2)
QueryUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
3)
ModifyUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
4)
DeleteUserMenu
if [ $? -ne 0 ];then
INSTALLFLAG=0
fi
break
;;
0)
INSTALLFLAG=0
break
;;
*)
Log 2 " Input error !"
esac
done
return 0
}
################ 提示处理函数 #####################
usage()
{
echo " usage"
echo " $0 <db_host_ip> <db_user_name> <db_pass_word>"
return 0;
}
################ 主处理函数 #####################
Process()
{
DB_HOST=${1}
DB_USER=${2}
DB_PASS=${3}
#DB_NAME="${DATABASE_NAME_PREFIX}7"
MainMenu
#QueryServData
if [ $? -ne 0 ]; then
Log 2 "Clean table data error."
return 1
fi
return 0
}
################ 主函数 #########################
Main()
{
if [ $# -ne 3 ];then
Log 2 "Input illegal: $*"
usage $*
return 1
fi
Process $*
return 0
}
Main $*
更多推荐
已为社区贡献1条内容
所有评论(0)