#!/bin/bash

# ********************************************** ***************************** #
# File Name: 
# Description: 
# Input: 
# Output: 
# Author: 
# Created: 
# Function List：
# History 
# 1.Date: 
#   Author: 
#   Modification: 
# **************************************************************************** #
trap '' 20
trap "OS_KILL_CMD" 2


# --------------------------  variables  ------------------------------------- #
#变量定义
G_CMD_PARAM=""
G_SUB_PARAM=""
G_USER=""
G_USER_TYPE=""
# Replacing the command to delete binary file of realpath.
G_REALPATH_CMD="/usr/bin/readlink -f"
#开放的命令列表
G_ALLOWED_CMD_LIST_FILE="/usr/local/etc/os_debug_mode_cmd_list"
#允许访问目录的文件
G_ALLOWED_ACCESSED_FILE="/usr/local/etc/sftppermit.config"
#不允许访问目录的文件
G_DENIED_ACCESSED_FILE="/usr/local/etc/sftpdeny.config"
#下列命令只能在某些目录下执行
G_ALLOWED_SPECIAL_CMD=("ls" "rm" "mv" "cd" "cat" "mount" "du" "grep")
G_ALLOWED_PARAM_CMD=("showdiskinfo" "telnet" "ip" "df" "ifconfig" "showsystrace" "os_backup_info.sh" "os_change_bayconfig.sh" "os_write_bay_cfg.sh" "os_upgrade_hotpatch.sh" "sysforcepoweron" "os_change_tp.sh" "sshtoremoteExt" "getremotefile" "getremotedir" "showrootfsinfo" "showresetinfo" "rebootsys" "showtdmcomm" "settdmcomm" "changeetherrorcoderule" "changememalarmpara" "setnumaswitch" "setdimmrule" "deldimmrule" "setrepairthrd")
G_DISK_MOUNT=/dev/sda
G_MIN_MEM=430
G_EMERGENCY_CMD=("kill" "rm")
G_CURRENT_EXIST_CMD=("cat" "cd" "date" "disktool" "du" "free" "grep" "hwclock" "iostat" "kill" "ls"
            "lsscsi" "mount" "mv" "ps" "rm" "top" "umount" "ping"  "arp" "ip" "route" "netstat"
            "os_change_tp.sh")
G_NO_NEED_SUDO_CMD=("cd")
G_VERIFICATION_AND_DANGER_CMD=("cleardb" "logzonefreelogbylogid.sh" "modifydbtableinfo.sh")
G_ALL_REPLACE_PARAM_CMD=("om_show_omm_info.sh")
G_USER=$1
seg_ip=$2
G_ERR_ID=$3
G_ERR=$4


G_USER_TYPE=`cat /etc/passwd | awk -F: '{if($1 == var) print $4}' var=$G_USER`
L_MY_PID=$$

#检查用户是否合法，该模式只允许admin和对端通过心跳口使用
if [ "$G_USER" == "ibc_os_hs" -a "${seg_ip}" == "127.127.127" ];then
	/bin/bash
	exit
elif [ "$G_USER_TYPE" != "0" ];then
        if [ -f /OSM/log/runlog/sys_power_on_record ];then
        	echo "The minisystem mode is allowed for a super user only"
		exit
        fi
	sudo /OSM/script/os_debug_mode_process_guest.sh $G_USER
        exit
fi

#P12V-2045 modefied 2012/9/19 end
#包含头脚本
source /OSM/script/ocean_load_base.sh
# --------------------------  functions  ----------------------- ------------- #
# **************************************************************************** #
# Function Name: OS_PRINT_SYSTEM_INFO
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #

#2018/1/9
source /OSM/script/cli_verification_danger_funtion.sh
# **************************************************************************** #
# Function Name: CLI_VERIFICATION_AND_DANGER
# Description:白名单防呆处理，增加验证码输入与高危提示
# Parameter:
# Return: 0-防呆验证成功/不需要防呆; 1-防呆验证不成功
# **************************************************************************** #

OS_PRINT_SYSTEM_INFO()
{
        if [ -f /OSM/conf/versions.conf ];then
        L_PRODUCT_VERSION=`cat /OSM/conf/versions.conf | grep "^SpcVersion=" -m 1 2>/dev/null`
        L_PRODUCT_VERSION=${L_PRODUCT_VERSION:11:11}
        L_SYSTEM_VERSION=`cat /OSM/conf/versions.conf | grep "^Version=" | sed -n '2p' 2>/dev/null`
        L_SYSTEM_VERSION=${L_SYSTEM_VERSION:8:1}.${L_SYSTEM_VERSION:9:2}.${L_SYSTEM_VERSION:11:2}.${L_SYSTEM_VERSION:13:3}
        L_PATCH_VERSION=`cat /OSM/conf/versions.conf | grep "^SpcVersion=" -m 1 2>/dev/null`
        L_PATCH_VERSION=${L_PATCH_VERSION:22:6}
        L_COMPILE_TIME=`cat /OSM/conf/versions.conf | grep "^Time=" -m 1 2>/dev/null`
        L_COMPILE_TIME=${L_COMPILE_TIME:5:19}
        if [ -n "${L_PRODUCT_VERSION}" -a -n "${L_SYSTEM_VERSION}" -a -n "${L_COMPILE_TIME}" ];then
            echo "-----------------System Information-----------------"
            echo "|  Product Version     |   ${L_PRODUCT_VERSION}             |"
            echo "|  System  Version     |   ${L_SYSTEM_VERSION}             |"
            if [ -n "${L_PATCH_VERSION}" ];then
	        echo "|  Patch   Version     |   ${L_PATCH_VERSION}                  |"
	    else
	        echo "|  Patch   Version     |   "      "                       |"
	    fi
            echo "|  Release Time        |   ${L_COMPILE_TIME}     |"
            echo "----------------------------------------------------"
        fi
    fi
}

# **************************************************************************** #
# Function Name: OS_KILL_CMD
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_KILL_CMD()
{
    return 0
}

# **************************************************************************** #
# Function Name: OS_CHECK_CURRENT_EXIST_CMD
# Description:
# Parameter: cmd needed to check
# Return: exist 1, otherwise 0
# **************************************************************************** #
OS_CHECK_CURRENT_EXIST_CMD()
{
    local CMD_NEED_CHECK=$1

    for cmd in ${G_CURRENT_EXIST_CMD[@]}
    do
        if [ "${cmd}" == "${CMD_NEED_CHECK}" ];then
            return 1
        fi
    done

    return 0
}

#P12V-1984 modified 2012/9/10 begin
# **************************************************************************** #
# Function Name: OS_PRINT_HELP_INFO
# Description:
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_PRINT_HELP_INFO()
{
    local L_LINUX_CMDS=
    echo "Supported commands in minisystem mode:"            
    echo "exit          : quit"         
    echo "help          : show usage"           
    echo "rebootsys [opt]: reboot system"            
    echo "setupsystem   : format and re-install system"
    echo "showversion   : show versions"            
    echo "showbootmode  : show boot mode"
    echo "showdiskinfo  : show disk info"
    echo "upgradesystem : upgrade system software"
    echo "showsysstatus : show system status"
    echo "showsystrace [FlowId] : show system trace"
    echo "exportmemdb   : export memory db"
    echo "cleardb       : clear db in all mediums begin"
    echo "resumebootmode: resume boot mode from rescue to normal"
    echo "sshtoremote : ssh to peer via bond0 with ${G_USER}"
    echo "sshtoremoteExt [SlotId] : ssh to the controller specified by SlotId with ${G_USER}"
    echo "iprulelist : list ip rules"
    #SR-0000288844-支持小系统日志收集 added on 2013-10-18 begin
    echo "os_backup_info.sh [-f xxx.tar.bz2] [-a] [-F] | [-p] : collect logs"
    echo "                  -f: specify the saved log package name"
    echo "                  -a: backup all log files"
    echo "                  -F: backup log files without size limitation"
    echo "                  -p: check whether memory is sufficient or not"
    #SR-0000288844-支持小系统日志收集 added on 2013-10-18 end
    #AR-0000762469-支持6U4C的2扩4方案 added on 2014-05-22 begin
    echo "os_change_bayconfig.sh [delete] | [change] | [set] | [sync]: change bay config for BMC"
    #AR-0000762469-支持6U4C的2扩4方案 added on 2014-05-22 end
    echo "sysforcepoweron [switch flag] : set force power on switch flag [0:open,1:close]"
    echo "os_write_bay_cfg.sh [-i BayID] [-c ControllerTotal] [-t BayType] [-n] [-l] [-s] [-d]|[-a]"
    echo "os_upgrade_hotpatch.sh [-m size] [-w install|roll|delete] [-p package name [mini] ] [-g package name] [-c] [-r] [-k] [-d] [-s [1|2] ] [-v all|local|peertolocal] [-h] : upgrade hotpatch interface"
    echo "os_change_tp.sh { -a | -d } -f func -t type -i alive -p param : change tracepoint config file"
    echo "changeibckey : replace ibc_os_hs's key files to the home directory of ibc_os_hs"
    echo "getremotefile ip src_file dst_dir : transfer file between controllers"
    echo "getremotedir ip src_dir dst_dir : transfer dir between controllers"
    echo "telnet IPv4|IPv6 port(1~65535) : The telnet command is used to check whether the client port is open."
    echo "df -h : obtain the overall usage of disks"
    echo "showrootfsinfo : The showrootfsinfo command is used to query files in the cache and print the files into the messages file."
    echo "showresetinfo : The showresetinfo command is used to query the reset cause and time recorded by nvram."
    echo "showbayconfig : The showbayconfig command is used to show the bay information in memory and disks, including the enclosure ID, number of controllers and so on."
    echo "updatebios : The updatebios command is used to restart and update bios of this controller."
    echo "resumebios : The resumebios command is used to restart and resume bios of this controller."
    echo "enableiocfw : The enableiocfw command is used to update firmware of ioc smartio cards of this controller."
    echo "disableiocfw : The disableiocfw command is used to resume firmware of ioc smartio cards of this controller."
    echo "showtdmcomm [ctrlid] : The showtdmcomm command is used to show the tdm communication flag."
    echo "settdmcomm [ctrlid] [enable] : The settdmcomm command is used to set the the tdm communication flag, the parameter enable need 0(disable) or 1(enable)."
    echo "upgradesmm : The upgradesmmcpld command is used to update the CPLD firmware of management module 0."
    echo "rollbacksmm : The rollbacksmmcpld command is used to resume the CPLD firmware of management module 0."
    echo "checkupgradesmmversion : The checkupgradesmmversion command is used to check CPLD firmware versions of management module 0 after upgrade."
    echo "checkrollbacksmmversion : The checkrollbacksmmversion command is used to check CPLD firmware versions of management module 0 after roll back."
    echo "changeetherrorcoderule [period] [threshold] [times]: The changeetherrorcoderule command is used to set the eth port bit error alarm policy of this controller. the parameter period unit: second."
    echo "showetherrorcoderule : The showfcerrorcoderule command is used to query the eth port bit error alarm policy of this controller."
    echo "shownumaswitch : The shownumaswitch command is used to show the numa switch of this controller."
    echo "setnumaswitch [switch] : The setnumaswitch command is used to set the the numa switch of this controller, the parameter switch need 0(disable) or 1(enable)."
    echo "bpi2crepair : The bpi2crepair command is used to repair the I2C devices of the 3U backplane ."
    echo "showmemalarmpara: The showmemalarmpara command is used to show memory alarm threshold"
    echo "changememalarmpara [p1~p9]:  The changememalarmpara command is used to set memory alarm threshold, there are 9 parameters :
                                       Number of memory multi-address solid failure
                                       Days of memory multi-address solid failure
                                       Days of memory multi-bank error
                                       Days of multi-dimm error
                                       Days range of memory long time error
                                       Days of memory long time error
                                       Number of memory error per day
                                       Hours of memory ce storm
                                       Number of memory ce per hour"
    echo "setdimmrule [vendor] [modulepn] [batch] [ruleid] : The setdimmrule command it used to config the dimm rule."
    echo "deldimmrule [index] : The deldimmrule command is used to delete the dimm rule by index."
    echo "showdimmrule: The showdimmrule command it used to show dimm rule."
    echo "setrepairthrd [cardtype] [time_threshold] [count_threshold]: The setrepairthrd command it used to set the interface card repair threshold. cardtype(0:front-end card 1:back-end card)"
    echo "showrepairthrd: The showrepairthrd command it used to show the interface card repair threshold."
    
    if [ -f ${G_ALLOWED_CMD_LIST_FILE} ]; then
        count=0
        product_name=`cat /OSM/conf/product.ini | grep "^ProductName=" -m 1 2>/dev/null`
        while read line
        do
            if [ -z "$line" ]; then
                continue
            fi
            if [ "restore_sysenclosure_info.sh" == "$line" ]; then  
                if [ "ProductName=2600 V3" != "$product_name" ];then
		    if [ "ProductName=2600F V3" != "$product_name" ];then
                    continue;
                    fi
                fi
            fi
            OS_CHECK_CURRENT_EXIST_CMD ${line}
            ret=$?
            if [ 1 -eq "$ret" ]; then
                continue

            else
                if [ -n "`echo ${line} | grep "\.sh$"`" ];then
                    help_info=`${line} -h`
                    [ -n "$help_info" ] && echo $help_info
                else
                    ((count++))
                    # 每六个命令换行一次，因此插入逗号，方便匹配替换
                    if [ $count -eq 6 ]; then
                        count=0;
                        L_LINUX_CMDS=${L_LINUX_CMDS}${line}","
                    else
                        L_LINUX_CMDS=${L_LINUX_CMDS}${line}" "
                    fi
                fi
            fi
        done<${G_ALLOWED_CMD_LIST_FILE}
    fi

    echo "Other command supported:"
    echo "cat cd date disktool"
    echo "du free grep hwclock ifconfig"
    echo "iostat kill ls lsscsi mount ping"
    echo "mv ps rm top umount"
    echo "arp ip route netstat"
    [ -n "$L_LINUX_CMDS" ] && echo ${L_LINUX_CMDS%?} | sed "s/,/\n/g"
    return 0
}
#P12V-1984 modified 2012/9/10 end

# **************************************************************************** #
# Function Name: OS_PERMITDIR_CHECK
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_PERMITDIR_CHECK()
{
    local L_CHECK_DIR=$1
    local L_RESULT="0"
    L_CHECK_DIR=`${G_REALPATH_CMD} ${L_CHECK_DIR}`
    
    while read line 
    do             
        L_RESULT=`expr match ${L_CHECK_DIR} ${line} 2>/dev/null`
        if [ "${L_RESULT}" != "0" ];then 
            return 1 
        fi 
    done<${G_DENIED_ACCESSED_FILE}
    
    while read line
    do            
        L_RESULT=`expr match ${L_CHECK_DIR} ${line} 2>/dev/null`
        if [ "${L_RESULT}" != "0" ];then
            return 0
        fi
    done<${G_ALLOWED_ACCESSED_FILE}

    return 1
}

# **************************************************************************** #
# Function Name: OS_CHECK_OP_VALID
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_CHECK_OP_VALID()
{
    local L_CMD_OP=$1
    local L_CMD_DATA=$2
    local L_RET=0

    for cmd in ${G_ALLOWED_SPECIAL_CMD[@]}
    do
        if [ "${cmd}" == "${L_CMD_OP}" ];then
            for dir in ${L_CMD_DATA} 
            do
               if [ ${dir:0:1} = "-" ]; then
                    continue;
               fi


                if [ "${cmd}" == "mount" ];then
                    L_DEV=`echo ${dir} | grep "^/dev"`
                    #包含/dev字符串，允许mount
                    if [ -n "${L_DEV}" ];then
                        continue
                    fi
                fi
                
                OS_PERMITDIR_CHECK "${dir}"
                L_RET=$?
                if [ "$L_RET" != "0" ];then
                    return 1
                fi
            done
        fi
    done

    return 0
}
# **************************************************************************** #
# Function Name: OS_CHECK_RPLACE_PARAMCMD_VALID
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_CHECK_RPLACE_PARAMCMD_VALID()
{
    local L_CMD=`echo $G_CMD_PARAM | awk '{print $1}'`

    for cmd in ${G_ALL_REPLACE_PARAM_CMD[@]}
    do
        if [ "${cmd}" == "${L_CMD}" ];then
            return 0
        fi
    done
    [ -n "$(echo "$G_CMD_PARAM" | grep '\\')" ] && { echo "This mode not support command with execution character!"; return 1; }
	
    return 0
}
# **************************************************************************** #
# Function Name: OS_CHECK_PARAMCMD_VALID
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_CHECK_PARAMCMD_VALID()
{
    local L_CMD=`echo $G_CMD_PARAM | awk '{print $1}'`

    for cmd in ${G_ALLOWED_PARAM_CMD[@]}
    do
        if [ "${cmd}" == "${L_CMD}" ];then
            G_SUB_PARAM=$L_CMD
            break
        fi
    done

    return 0
}
# **************************************************************************** #
# Function Name: OS_CHECK_CMD_VALID
# Description: 
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_CHECK_CMD_VALID()
{
    local L_PWD=`pwd`
    #local L_CMD_TMP=`echo ${G_CMD_PARAM} | cut -d" " -f 1`
    #local L_CMD_EXECUTE=${L_CMD_TMP##*/}
    local L_CMD_EXECUTE=`echo ${G_CMD_PARAM} | cut -d" " -f 1`
    local L_CMD_LENGTH=${#L_CMD_EXECUTE}
    local L_CMD_DATA=${G_CMD_PARAM:$L_CMD_LENGTH}
    L_CMD_DATA=${L_CMD_DATA%"|"*}
    #P11G-5413 modified 2012/9/10 begin

    for line in ${G_CURRENT_EXIST_CMD[@]}
    do
        if [ "${line}" == "${L_CMD_EXECUTE}" ];then
            if [ -z "${L_CMD_DATA}" ];then
                return 0
            fi
            #对于特殊命令，需要限制操作范围，比如，文件路径等
            OS_CHECK_OP_VALID "${L_CMD_EXECUTE}" "${L_CMD_DATA}"
            if [ "$?" == "0" ];then
                return 0
            else
                echo "${G_CMD_PARAM} : Permission denied."
                return 1
            fi
        fi
    done

    if [ -f ${G_ALLOWED_CMD_LIST_FILE} ]; then
        while read line
        do
            if [ "${line}" == "${L_CMD_EXECUTE}" ];then
                if [ -z "${L_CMD_DATA}" ];then
                    return 0
                fi
                #对于特殊命令，需要限制操作范围，比如，文件路径等
                OS_CHECK_OP_VALID "${L_CMD_EXECUTE}" "${L_CMD_DATA}"
                if [ "$?" == "0" ];then
                    return 0
                else
                    echo "${G_CMD_PARAM} : Permission denied."
                    return 1
                fi
            fi
        done<${G_ALLOWED_CMD_LIST_FILE}
    fi

    #P11G-5512 modified 2012/10/8 begin
    echo "Error : Command '${G_CMD_PARAM}' does not exist or has an incorrect format."
    echo "Try 'help' for more information."
    #P11G-5512 modified 2012/10/8 end
    
    return 1
}

# **************************************************************************** #
# Function Name: OS_CHECK_NO_NEED_SUDO_CMD
# Description: if eth checked cmd is listed in G_NO_NEED_SUDO_CMD, return 1
# Parameter: cmd needed to check
# Return: exist 1, otherwise 0
# **************************************************************************** #
OS_CHECK_NO_NEED_SUDO_CMD()
{
    local CMD_NO_NEED_SUDO=$1

    for cmd in ${G_NO_NEED_SUDO_CMD[@]}
    do
        if [ "${cmd}" == "${CMD_NO_NEED_SUDO}" ];then
            return 1
        fi
    done

    return 0
}

    #P11G-5413 modified 2012/9/10 end
    
# **************************************************************************** #
# Function Name: OS_EXECUTE_DEBUG_CMD
# Description: 
#因为SysV的规定，当字符串中包含管道时，无法执行
#目前只支持最多10个管道的命令，暂时实现方法，后续有
#更好的方法，可以优化
# Parameter: 
# Return: success 0, otherwise 1
# **************************************************************************** #
OS_EXECUTE_DEBUG_CMD()
{
    declare -a split_array=()
    local split_argv1=${G_CMD_PARAM}
    local split_argv_tmp=${G_CMD_PARAM}
    if echo ${split_argv_tmp} | grep -w 'vi' >/dev/null 2>/dev/null
    then
    split_argv1=`echo ${split_argv_tmp} | sed "s#vi#vi -Z#g"`
    fi
    local split_argv2="|"
    if [ "$split_argv2" == "" ];then 
        return 1 
    fi 

    split_len=0 

    break_len=${#split_argv2} 

    #判断是否包含分隔符
    index=`expr index "$split_argv1" "$split_argv2"` 

    while [[ "$index" -gt "0" ]] 
    do 
        #获得分割好的字符串 
        split_array[$split_len]=${split_argv1:0:$index-1} 
        split_len=$split_len+1

        #记录截断的字符串 
        split_argv1=${split_argv1:$index-1+break_len} 
        index=`expr index "$split_argv1" "$split_argv2"` 
    done 

    #把最后一个保存 到数组中
    split_array[$split_len]=$split_argv1
    
    alen=${#split_array[*]}

    OS_CHECK_NO_NEED_SUDO_CMD ${split_array[0]}
    if [ 1 -eq "$?" ]; then
        case $alen in
            1)
                ${split_array[0]}
                ;;
            2)
                ${split_array[0]}|${split_array[1]}
                ;;
            3)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}
                ;;
            4)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}
                ;;
            5)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}
                ;;
            6)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}
                ;;
            7)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}
                ;;
            8)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}
                ;;
            9)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[7]}         
                ;;
            10)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[8]}|${split_array[9]}
                ;;
            11)
                ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[8]}|${split_array[9]} |${split_array[10]}           
                ;;
            *)
                ;;
        esac
    else
        case $alen in
            1)
                sudo ${split_array[0]}
                ;;
            2)
                sudo ${split_array[0]}|${split_array[1]}
                ;;
            3)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}
                ;;
            4)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}
                ;;
            5)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}
                ;;
            6)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}
                ;;
            7)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}
                ;;
            8)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}
                ;;
            9)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[7]}         
                ;;
            10)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[8]}|${split_array[9]}
                ;;
            11)
                sudo ${split_array[0]}|${split_array[1]}|${split_array[2]}|${split_array[3]}|${split_array[4]}|${split_array[5]}|${split_array[6]}|${split_array[7]}|${split_array[8]}|${split_array[9]} |${split_array[10]}           
                ;;
            *)
                ;;
        esac
    fi

    if [ "$?" != 0 ];then
        return 1
    fi

    return 0
}



# **************************************************************************** #
# Function Name: OS_ALARM_CMD_EMERGENCY
# Description:检查待执行命令是否为高危命令
# Parameter:
# Return: 1-是; 0-否
# **************************************************************************** #
OS_ALARM_CMD_EMERGENCY()
{
    local L_CMD_EG=`echo ${G_SUB_PARAM} | cut -d" " -f 1`
    for cmd in ${G_EMERGENCY_CMD[@]}
    do
        if [ "${cmd}" == "${L_CMD_EG}" ]; then
            return 1
        fi
    done
    
    return 0
}

# **************************************************************************** #
# Function Name: OS_CHECK_HELP_CMD
# Description:检查待执行命令是否为查看帮助的命令
# Parameter:
# Return: 1-是; 0-否
# **************************************************************************** #
OS_CHECK_HELP_CMD()
{
    local L_CMD_SEG=`echo ${G_SUB_PARAM} | cut -d" " -f 2`
    if [ "${L_CMD_SEG}" == "-h" -o "${L_CMD_SEG}" == "--help" ]; then
        return 1
    fi
     return 0
}
# **************************************************************************** #
# Function Name: print upgrade smm result
# Description: if eth checked cmd is listed in G_NO_NEED_SUDO_CMD, return 1
# Parameter: cmd needed to check
# Return: exist 1, otherwise 0
# **************************************************************************** #

DMI_PRINT_RESULT()
{
    local RESULT=$1
    case $RESULT in
        0) echo "Status: Success."
           echo "Detail: Command execute success.";;   
        1) echo "Status: Success."
           echo "Detail: Management module version same no need upgrade.";;
        2) echo "Status: Retry."
           echo "Detail: Management module version is upgrading please wait 2 min.";; 
        3) echo "Status: Fail."
           echo "Detail: Management module prepare failed $ret.";; 
        4) echo "Status: Fail."
           echo "Detail: Management module prepare check state failed $ret.";;
        5) echo "Status: Fail."
           echo "Detail: Management module sendfile failed $ret.";;
        6) echo "Status: Fail."
           echo "Detail: Management module sendfile check state failed $ret.";;
        7) echo "Status: Fail."
           echo "Detail: Management module start upgrade failed $ret.";;
        8) echo "Status: Fail."
           echo "Detail: Management module version check failed.";;
        9) echo "Status: Fail."
           echo "Detail: Management module input para error.";; 
        10)echo "Status: Fail."
           echo "Detail: Management module can not find firmware package.";; 
        11)echo "Status: Fail."
           echo "Detail: Management module can not find firmware.";; 
        *) echo "Status: Fail."
           echo "Detail: Management module $condition.";;
    esac
}

# --------------------------  main  ------------------------------------------ #
G_WHERE=`who -m | awk '{print $2$6}'`

OS_echo "[minisystem]$G_USER login minisystem(pid=$L_MY_PID) from $G_WHERE."

G_SYS_RECORD_STATUS=/OSM/log/runlog/sys_power_on_record
G_PRINTINFO=0
#打印系统信息
if [ -f $G_SYS_RECORD_STATUS ];then
   if [ -n "$G_ERR" -o -n "$G_ERR_ID" ];then
          G_PRINTINFO=1
          OS_PRINT_SYSTEM_INFO
   fi
else
   G_PRINTINFO=1
   OS_PRINT_SYSTEM_INFO
fi

#os_rescue模式特殊处理
oSRescue=`cat /proc/cmdline | grep os_rescue`
if [ -n "$oSRescue" ];then
  if [ "${G_PRINTINFO}" == 0 ];then
    OS_PRINT_SYSTEM_INFO
  fi
fi


#打印错误信息
if [ -f /OSM/script/ErrCodeFunc.sh ];then
        source /OSM/script/ErrCodeFunc.sh
        if [ -f $G_SYS_RECORD_STATUS -a -z "$G_ERR" ];then
          if [ -z "$G_ERR_ID" -a -z "$oSRescue" ];then
              sh /ISM/cli/start.sh -u admin
              exit
          fi
        fi

        if [ -n "$G_ERR_ID" -a -n "$G_ERR" ];then
                showErrorInfo "$G_ERR_ID" "$G_ERR"
        elif [ -n "$G_ERR_ID" ];then
            showErrorInfo "$G_ERR_ID"
        fi
else
        OS_echo "[minisystem]/OSM/script/ErrCodeFunc.sh is not exist, can't show error_info."
fi



PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin:/usr/local/OSM/script:/OSM/bin:/OSM/bin/script:/OSM/script
export PATH
OS_echo "[minisystem]admin login minisystem(pid=$L_MY_PID)."

#切换到用户主目录
cd /home/permitdir

#主循环
L_PROMPT="$(hostname): minisystem> "
while true
do       
    L_FD=`ls -l /proc/$L_MY_PID/fd/0 2>/dev/null | awk '{print $9 $10 $11 $12}' | grep deleted`
    if [ "${L_FD}x" != "x" ];then
        OS_echo "[minisystem]stdin-fd deleted already, so auto-exit minisystem(pid=$L_MY_PID)."
        exit 1
    fi
    G_CMD_PARAM=""
    read -p "$L_PROMPT" G_CMD_PARAM
    [ $? -ne 0 ] && echo " " && exit 1

    if [ -z "$G_CMD_PARAM" ];then
        continue
    fi

    if [ -n "$G_CMD_PARAM" ];then
        OS_RECORD_HISTORY_CMD "$G_CMD_PARAM" "ospcli_history"
    fi
    [ -n "$(echo "$G_CMD_PARAM" | grep '|')" ] && { echo "This mode not support command with pipe!"; continue; }
    [ -n "$(echo "$G_CMD_PARAM" | grep ';')" ] && { echo "This mode not support command with semicolon!"; continue; }
    [ -n "$(echo "$G_CMD_PARAM" | grep '&')" ] && { echo "This mode not support command with and!"; continue; }
    [ -n "$(echo "$G_CMD_PARAM" | grep '\$')" ] && { echo "This mode not support command with dollar!"; continue; }
    [ -n "$(echo "$G_CMD_PARAM" | grep '`')" ] && { echo "This mode not support command with execution character!"; continue; }
    [ -n "$(echo "$G_CMD_PARAM" | grep '>')" ] && { echo "This mode not support command with execution character!"; continue; }
    OS_CHECK_RPLACE_PARAMCMD_VALID
    if [ $? != 0 ];then
        continue
    fi 
	
    G_SUB_PARAM=$G_CMD_PARAM
    OS_CHECK_PARAMCMD_VALID
    case ${G_SUB_PARAM} in
           "exit")
                echo "Are you sure to exit?(y/n)"
                read -p "" L_INPUT
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                    OS_echo "[minisystem]admin logout minisystem(pid=$L_MY_PID)."
                    exit
                fi
                ;;
            "help")
                OS_PRINT_HELP_INFO
                ;;
            "rebootsys")
			
                echo "Are you sure to restart this controller?(y/n)"
                read -p "" L_INPUT
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                    L_INSMOD_OSPSYS=`lsmod |awk '{print $1}' | grep 'sysctrl'`
                    if [ -z "$L_INSMOD_OSPSYS" ] ; then
                    	sudo reboot -f
                    	continue
                    fi
                    					
                    L_FORCE_FALG=`echo "$G_CMD_PARAM" | awk '{print $2}'`   
                    if [ -z "$L_FORCE_FALG" ];then   
                    	echo 'reboot controller'
                    	echo -e "sys ministopfd\nexit\n" | diagnose --auto
                    else
                    	if [ "force" == "$L_FORCE_FALG" ];then   
                    	   echo "reboot controller operate($L_FORCE_FALG):"   
                    	   sudo reboot -f
                    	   continue
                    	else
                    	    echo "Invalid parameter, if you want to force reboot it, please execute 'rebootsys force'."   
                    	    continue
                    	fi
                    fi  

                fi 
                ;;
            "setupsystem")    
                L_PWD=`pwd`
                if [ ! -f /home/permitdir/OceanStor_*.tgz ];then                    
                    sudo /OSM/script/os_check_sys_free_mem.sh "${G_MIN_MEM}"
                    if [ 0 != "$?" ];then
                        echo "Re-install system failed,current system memory is lower to ${G_MIN_MEM}M."
                        continue
                    fi 
                fi
                echo "Make sure you have uploaded package to /home/permitdir/"          
                read -p "Input package name:" L_PKG_NAME            
                if [ -n "$L_PKG_NAME" ];then                
                    L_TYPE=$(OS_GET_HW_TYPE)
                    sudo /OSM/script/os_setup_disk.sh -p /home/permitdir/$L_PKG_NAME -d /dev/sda -t $L_TYPE
                    if [ "$?" == "0" ];then                 
                       echo "Re-install system success, you must restart the system for the change to take effect."                
                    else                    
                       echo "Re-install system failed, reboot system is dangerous, please setupsystem again."              
                    fi              
                else                
                    echo "package name can not be empty"            
                fi
                cd ${L_PWD} &>/dev/null
                ;;
    #问题单号:P12N-5156   时间:20121109 begin      
            "showversion")          
                if [ -f /OSM/conf/versions.conf ];then              
                    echo "Product Version  |  ${L_PRODUCT_VERSION}"             
                    echo "System  Version  |  ${L_SYSTEM_VERSION}"              
                    echo "Release Time     |  ${L_COMPILE_TIME}"            
                else                
                    echo "version file is not exist"            
                fi          
                ;;      
            "showbootmode") 
                L_PWD=`pwd`
                if [ -L /startup_disk/image/boot ];then             
                    cd /startup_disk/image &>/dev/null              
                    ls -l boot 2>/dev/null             
                    cd / &>/dev/null            
                else                
                    echo "boot link is not exist"           
                fi
                cd ${L_PWD} &>/dev/null
                ;;   
            "showrootfsinfo") 

                eval sudo /OSM/script/show_rootfs_files_info.sh ${G_CMD_PARAM#showrootfsinfo}
                ;; 
            "showresetinfo") 
                sudo /OSM/script/upgrade.sh -s
                ;;
            "showbayconfig") 
                sudo /OSM/script/os_show_bay_cfg.sh
               ;;                
            "resumebootmode") 
                L_PWD=`pwd`
                sudo /OSM/script/os_resume_boot_mode.sh
                if [ "$?" != "0" ];then
                    cd ${L_PWD} &>/dev/null
                    continue
                fi

                cd ${L_PWD} &>/dev/null
                ;;
            "upgradesystem")
                L_PWD=`pwd`
                sudo /OSM/script/os_upgrade_system.sh
                if [ "$?" != "0" ];then
                    cd ${L_PWD} &>/dev/null
                    continue
                fi

                cd ${L_PWD} &>/dev/null
                ;;
            "showsysstatus")
                L_INSMOD_OSPSYS=`lsmod |awk '{print $1}' | grep 'sysctrl'`
                if [ -z "$L_INSMOD_OSPSYS" ] ; then
                    echo 'The command do not execute.'
                    continue
                fi
                              
                echo "Show system status"
                echo -e "sys showcls\nexit\n" | diagnose --auto
                ;;
        "showsystrace")   
                L_INSMOD_OSPSYS=`lsmod |awk '{print $1}' | grep 'sysctrl'`   
                if [ -z "$L_INSMOD_OSPSYS" ] ; then   
                    echo 'The command do not execute.'   
                    continue   
                fi   
                     
               L_FLOW_ID=`echo "$G_CMD_PARAM" | awk '{print $2}'`   
               if [ -z "$L_FLOW_ID" ];then   
                   echo 'Show flow all:'
                   echo -e "sys showtrace\nexit\n" | diagnose --auto
               else
                   echo "Show system flow($L_FLOW_ID):"   
                   echo -e "sys showtrace $L_FLOW_ID\nexit\n" | diagnose --auto  
               fi   
               ;;
            "exportmemdb")
                L_INSMOD_EXPORTMEMDB=`lsmod |awk '{print $1}' | grep 'dbapp'`
                L_INSMOD_EXPORTMEMDBB=`lsmod |awk '{print $1}' | grep 'dbmanage'`
                if [ -z "$L_INSMOD_EXPORTMEMDB" -o -z "$L_INSMOD_EXPORTMEMDBB" ] ; then
                    echo 'The command do not execute.'
                    continue
                fi
                
                echo "Export db from memory begin......"
                echo -e "db exportdb\nexit\n" | diagnose --auto
                ;;
            "cleardb")
                L_INSMOD_DB=`lsmod |awk '{print $1}' | grep 'dbapp'`
                if [ -z "$L_INSMOD_DB" ] ; then
                    echo 'The command do not execute.'
                    continue
                fi

                #白名单防呆处理，增加验证码输入与高危提示
                CLI_VERIFICATION_AND_DANGER
                if [ $? -ne 1 ]; then
                  cd ${L_PWD} &>/dev/null
                  continue
                fi
                
                echo "DANGER: You are going to clear the configuration data of the storage system and the previous configuration data will be lost."
                echo "Suggestion: Before you perform this operation, export the configuration data ."
                echo "Have you read danger alert message carefully?(y/n)"
                read -p "" L_INPUT
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                    echo "Clear db in all mediums begin......"
                    echo -e "db clearall\nexit\n" | diagnose --auto
                fi
        
        #P11G-5436  modified 2012/9/10 end 
                ;;
            "sshtoremote")
                echo "Ssh to peer via bond0 with ${G_USER}......"
                L_REMOTE_IBC_IP=`OS_GetRemoteIBCIP`
                L_PORT=`sudo /OSM/script/os_get_sshd_port.sh`
                ssh -p "${L_PORT}" ${G_USER}@${L_REMOTE_IBC_IP}
                ;;
            "sshtoremoteExt")
                L_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 2) print 1; else print 0}'`
                if [ "$L_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                L_SLOT_ID=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                L_OTHER_IBC_IP=`OS_GetIPBySlotId $L_SLOT_ID`
                if [ -z "$L_OTHER_IBC_IP" ]; then
                    echo "SlotId is invalid."
                    continue
                fi

                echo "Ssh to controller(SlotId=${L_SLOT_ID}) with ${G_USER}......"
                L_PORT=`sudo /OSM/script/os_get_sshd_port.sh`
                ssh -p "${L_PORT}" ${G_USER}@${L_OTHER_IBC_IP}
                ;;
            "getremotefile")
                L_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 4) print 1; else print 0}'`
                if [ "$L_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                L_IP=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                L_SRC_FILE=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                L_DST_FILE=`echo "$G_CMD_PARAM" | awk '{print $4}'`             
                if [ ! -d "${L_DST_FILE}" ];then
                    echo "${L_DST_FILE} is not exist." 
                    continue
                fi
                OS_PERMITDIR_CHECK "${L_DST_FILE}"            
                if [ $? != 0 ];then
                    echo "Permission denied."                   
                    continue
                fi                
                L_TMP=`echo $L_IP | grep "127.127.127"`    
                if [ -n "$L_TMP" ];then
                OS_PERMITDIR_CHECK "${L_SRC_FILE}"
                if [ $? != 0 ];then
                    echo "Permission denied."                
                    continue
                fi
                    sudo /OSM/script/os_get_file.sh "$L_IP" "$L_SRC_FILE" "$L_DST_FILE"
                else
                    L_CFG_ETH_SEG=`echo ${L_IP} | awk -F. '{print $1"."$2"."$3}'`
                    L_FTP_PROTOCOL="sftp://"
                    L_PORT=`sudo /OSM/script/os_get_sshd_port.sh`
                    L_LFTP_RET=/tmp/lftp_return_$$
                    sudo lftp -u ${G_USER} ${L_FTP_PROTOCOL}${L_IP}:"${L_PORT}" -e "set xfer:disk-full-fatal yes;set net:reconnect-interval-base 3;set net:max-retries 2;set net:timeout 30s;set xfer:clobber on;debug 4 -o ${L_LFTP_RET};get ${L_SRC_FILE} -o ${L_DST_FILE}; bye" &>/dev/null
                fi
                if [ $? != 0 ];then
                    echo "getremotefile failed."   
                    [ -f "${L_LFTP_RET}" ] && sudo cat "${L_LFTP_RET}"
                    [ -f "${L_LFTP_RET}" ] && sudo rm -f "${L_LFTP_RET}"
                    continue
                fi 
                echo "[getremotefile] execute successfully" 
                ;;            
            "getremotedir")
                L_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 4) print 1; else print 0}'`
                if [ "$L_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                L_IP=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                L_SRC_DIR=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                L_DST_DIR=`echo "$G_CMD_PARAM" | awk '{print $4}'`              
            
                OS_PERMITDIR_CHECK "${L_DST_DIR}"            
                if [ $? != 0 ];then
                    echo "Permission denied."                   
                    continue
                fi   
                L_TMP=`echo $L_IP | grep "127.127.127"`    
                if [ -n "$L_TMP" ];then
                    OS_PERMITDIR_CHECK "${L_SRC_DIR}"
                    if [ $? != 0 ];then
                        echo "Permission denied."                
                        continue
                    fi
                    sudo /OSM/script/os_get_dir.sh "$L_IP" "$L_SRC_DIR" "$L_DST_DIR" 
                else
                    L_CFG_ETH_SEG=`echo ${L_IP} | awk -F. '{print $1"."$2"."$3}'`
                    L_FTP_PROTOCOL="sftp://"
                    L_PORT=`sudo /OSM/script/os_get_sshd_port.sh`
                    G_SRC_DIR_NAME=${L_SRC_DIR##*/}
                    L_LFTP_RET=/tmp/lftp_return_$$
                    sudo lftp -u ${G_USER} ${L_FTP_PROTOCOL}${L_IP}:"${L_PORT}" -e "set xfer:disk-full-fatal yes;set net:reconnect-interval-base 3;set net:max-retries 2;set net:timeout 30s;set xfer:clobber on;debug 4 -o ${L_LFTP_RET};mirror ${L_SRC_DIR} ${L_DST_DIR}/${G_SRC_DIR_NAME}; bye" &>/dev/null
                fi
                if [ $? != 0 ];then
                    echo "getremotedir failed."  
                    [ -f "${L_LFTP_RET}" ] && sudo cat "${L_LFTP_RET}"
                    [ -f "${L_LFTP_RET}" ] && sudo rm -f "${L_LFTP_RET}"	
                    continue
                fi 
                echo "[getremotedir] execute successfully"
                ;;				
            "showdiskinfo")
                #检查sd模块是否已经加载
                L_INSMOD_BDMSD=`lsmod | grep 'sd ' | awk '{print $1}'`
                if [ -z "$L_INSMOD_BDMSD" ];then
                    echo 'The command do not execute.'
                    continue
                fi
                #需要执行的命令
                L_EXEC_SHOW_DEV="sddebug showdev"
                echo -e "${L_EXEC_SHOW_DEV}\nexit\n" | diagnose --auto
                ;;
            "iprulelist")
                L_RULE_LIST=/tmp/ip_rule_tmp
                ip rule list > $L_RULE_LIST
                if [ $? -eq 0 ];then
                    echo "==============================="
                    cat $L_RULE_LIST
                    echo "==============================="
                else
                    echo "Execute failed!"
                fi   
                ;;
			"ip")
				if [ -n "`echo "$G_CMD_PARAM" | grep -w "exec"`" ];then
					echo "command \"ip * exec *\" is forbided!"
				elif [ -n "`echo "$G_CMD_PARAM" | grep -w "bash"`" ];then
					echo "command \"ip * bash *\" is forbided!"
				else 
					L_TMP_RES=`echo "$G_CMD_PARAM" |grep -w "ip"`
					if [ -z "`echo $L_TMP_RES |grep -w "netns"`" -a -z "`echo $L_TMP_RES |grep -w "netn"`" -a -z "`echo $L_TMP_RES |grep -w "net"`" ];then
						sudo $G_CMD_PARAM
					else
						echo "command \"ip net* *\" is not supported!"
					fi	
				fi			
				;;
			#问题单DTS2016081606300
			"ifconfig")
				if [ -z "`echo  ${G_CMD_PARAM} | grep -w "tunnel"`" ];then
					sudo $G_CMD_PARAM
				else
					echo "Command \"ifconfig * tunnel *\" is not supported!"
				fi
				;;
			
            #SR-0000288844-支持小系统日志收集 added on 2013-10-18 begin
            "os_backup_info.sh")
                # if the inputted the parameter -f, the set f_flag=1
                f_flag=0
                # f_count means how many paramers after the parameter -f
                f_count=0
                L_PARAM1=" -d /OSM/coffer_data/omm/export_import"
                # the parameter para_check=0 means the inputted parameters are correct, not zero means wrong parameters
                para_check=0
                L_PARAM=${G_CMD_PARAM#os_backup_info.sh}
                if [ -n "${L_PARAM}" ];then
                    for param in ${L_PARAM}
                    do
                        if [ "${param}" == "-f" ];then
                            f_flag=1
                        elif [ "${f_count}" -eq 1 ];then
                            # after the parameter -f, the parameter must be the filename and its extension must be .tar.bz2
                            if [ "$(echo $param | awk -F'.' '{print $(NF-1)"."$NF}')" != "tar.bz2" ];then
                                echo "Parameter is not correct, the filename extension must be .tar.bz2."
                                para_check=1
                                break
                            fi
                        elif [ "${param}" != "-a" ] && [ "${param}" != "-F" ] && [ "${param}" != "-p" ];then
                            echo "Parameter is not correct, only the parameter -f, -a, -F and -p are supported."
                            para_check=1
                            break
                        fi
                        # the f_count add one to indicate how many paramers after the parameter -f
                        if [ "${f_flag}" -eq 1 ];then
                            f_count=$((f_count+1))
                        fi
                    done
                fi
				
                # after the parameter -f, must set the filename
                if [ "${f_flag}" -eq 1 ] && [ "${f_count}" -le 1 ];then
                    para_check=1
                    echo "After the parameter -f, must set the filename."
                fi
                if [ "${para_check}" -eq 0 ] && [ "${param}" == "-p" ];then
                    eval sudo /usr/bin/os_backup_info.sh $L_PARAM
                    backup_ret="$?"
                    if [ "${backup_ret}" -eq 0 -a -z "`echo "${L_PARAM}" | grep "[[:space:]]\-p[[:space:]]*$" 2>/dev/null`" ] || [ "${backup_ret}" -eq 2 ];then
                        echo "The log collection is finished, you can get the log from the directory /OSM/coffer_data/omm/export_import/."
                    fi
                elif [ "${para_check}" -eq 0 ] && [ "${param}" != "-p" ];then
                    L_PARAM=${L_PARAM}${L_PARAM1}
                    eval sudo /usr/bin/os_backup_info.sh $L_PARAM
                    backup_ret="$?"
                    if [ "${backup_ret}" -eq 0 -a -z "`echo "${L_PARAM}" | grep "[[:space:]]\-p[[:space:]]*$" 2>/dev/null`" ] || [ "${backup_ret}" -eq 2 ];then
                        echo "The log collection is finished, you can get the log from the directory /OSM/coffer_data/omm/export_import/."
                    fi
                fi
                ;;
            #SR-0000288844-支持小系统日志收集 added on 2013-10-18 end
            #AR-0000762469-支持6U4C的2扩4方案 added on 2014-05-22 begin
            "os_change_bayconfig.sh")
                L_BAY_PARAM=${G_CMD_PARAM#os_change_bayconfig.sh}
                eval sudo /OSM/script/os_change_bayconfig.sh $L_BAY_PARAM
                ;;
            #AR-0000762469-支持6U4C的2扩4方案 added on 2014-05-22 end
            "os_upgrade_hotpatch.sh")
	            if [ "`$G_REALPATH_CMD /startup_disk/image/boot`" != "/startup_disk/image/boot_osp" ];then
	                echo "The system is in rescue mode. After the \"resumebootmode\" command is executed successfully, run the \"os_upgrade_hotpatch.sh\" command."
	                continue
	            fi
                L_PARAM=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                L_HOTPATCH_PARAM=${G_CMD_PARAM#os_upgrade_hotpatch.sh}
                eval sudo setsid /OSM/script/os_upgrade_hotpatch.sh $L_HOTPATCH_PARAM
                ;;
            "os_write_bay_cfg.sh")
				L_BAYCFG_PARAM=${G_CMD_PARAM#os_write_bay_cfg.sh}
                m_ret=$(echo ${L_BAYCFG_PARAM} | grep -w "\-m")
				r_ret=$(echo ${L_BAYCFG_PARAM} | grep -w "\-r")
                if [ -n "$m_ret" -o -n "$r_ret" ]; then
                    eval sudo /OSM/script/os_write_bay_cfg.sh -h
                else
                    eval sudo /OSM/script/os_write_bay_cfg.sh $L_BAYCFG_PARAM
                fi
				;;
            "sysforcepoweron")   
                L_PARAM_NUM=`echo "$G_CMD_PARAM" | awk '{print NF}'`
                if [ ${L_PARAM_NUM} -ne 2 ];then
                    echo 'Input parameter number error!'
                    echo "Try 'help' for more information."
                    continue
                fi
                L_SWITCH_FLAG=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                if [ "${L_SWITCH_FLAG}" != "0" -a "${L_SWITCH_FLAG}" != "1" ];then
                   echo "Input parameter invalid!"
                   echo "Try 'help' for more information."
                   continue
                fi
                L_INSMOD_OSPSYS=`lsmod |awk '{print $1}' | grep 'sysctrl'`
                if [ -z "$L_INSMOD_OSPSYS" ] ; then
                    echo 'The command do not execute.'
                    continue
                fi
                echo -e "sys setforcepoweronswitch ${L_SWITCH_FLAG}\nexit\n" | diagnose --auto
                ;;
            "changeibckey")
                sudo /OSM/script/kmm_encrypt_ssh.sh update
                ;;
            "settdmcomm")
                setret=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 3) print 1; else print 0}'`
                if [ "$setret" -ne "0" ];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter number error! Try 'help' for more information."
                    continue
                fi
                ctrlid=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                enableflag=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                if [[ "$enableflag" -ne "0" && "$enableflag" -ne "1" ]];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter error! Flag must be 0 or 1."
                    continue
                fi
                if [[ "$ctrlid" -lt "0" || "$ctrlid" -gt "3" ]];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter error! Ctrlid must be 0 ~ 3."
                    continue
                fi
                result=(`ifconfig bond0 | grep -c "127.127.127.1${ctrlid}"`)
                if [ $result == 1 ]; then 
                    echo "Status: Fail."
                    echo "Detail: This cmd cannot exec on target controller. For example, if you want to isolate A controller, this cmd cannot exec on it."
                    continue
                fi
                result=(`echo -e "mpa bmc getchipmasterslave 400 0\nexit\n" | mml |grep -c "Chip MasterSlave Flag:0"`)
                if [ $result == 1 ]; then 
                    echo "Status: Fail."
                    echo "Detail: The Management is slave, Please Retry."
                    continue
                fi
                echo "Detail: Input Parameter are CTRL:$ctrlid, FLAG: $enableflag."
                #写0xBE寄存器,BIT0~BIT3分别代表A/B/C/D的隔离状态,0xBF代表写保护状态寄存器
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x4 0x0 0x0 0x92 0xBF 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Open Protected Cpldreg Fail, Please Retry."
                    continue
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x4 0x0 0x0 0x92 0xBE 0x0 0x0 0x0 ${ctrlid} 0x0 0x0 0x0 ${enableflag} 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    result=(`sudo ipmitool raw 0x32 0x71 0x0 0x4 0x0 0x0 0x92 0xBE 0x0 0x0 0x0 ${ctrlid} 0x0 0x0 0x0 ${enableflag} 0x0 0x0 0x0`)
                fi
                if [ $? == 0 ]; then 
                    echo "Status: Success."
                    echo "Detail: Set Tdm Comm Flag[$enableflag] for Ctrl[${ctrlid}] success."
                    OS_echo "Set Tdm Comm Flag[$enableflag] for Ctrl[${ctrlid}] success."
                else
                    echo "Status: Fail."
                    echo "Detail: Set Tdm Comm Flag Fail, Please Retry."
                fi
                ;;
            "showtdmcomm")
                showret=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 2) print 1; else print 0}'`
                if [ "$showret" -ne "0" ];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter number error! Try 'help' for more information."
                    continue
                fi
                ctrlid=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                if [[ "$ctrlid" -lt "0" || "$ctrlid" -gt "3" ]];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter error! Ctrlid must be 0 ~ 3."
                    continue
                fi
                #查询0xBE寄存器,BIT0~BIT3分别代表A/B/C/D的隔离状态
                result=(`sudo ipmitool raw 0x32 0x72 0x0 0x4 0x0 0x0 0x92 0xBE 0x0 0x0 0x0 ${ctrlid} 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    result=(`sudo ipmitool raw 0x32 0x72 0x0 0x4 0x0 0x0 0x92 0xBE 0x0 0x0 0x0 ${ctrlid} 0x0 0x0 0x0`)
                fi
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Show Tdm Comm Flag Fail, Please Retry."
                else
                    echo "Status: Success."
                    echo "Detail: Current Tdm Comm Flag For Ctrl[$ctrlid]: $result."
                    OS_echo "Current Tdm Comm Flag For Ctrl[$ctrlid]: $result."
                fi
                ;;
	    "telnet")
	        L_PARAM_NUM=`echo "$G_CMD_PARAM" | wc -w`
		if  [ $L_PARAM_NUM -ne 3 ];then
		    echo "paramers is not 2,please check your command"
		    echo "telnet IPv4|IPv6 port(1~65535):diagnose client telnet server status."
		    continue
		fi
		L_PARAM_IP=`echo "$G_CMD_PARAM" |awk '{print $2}'`
		ipv4_flag=`echo $L_PARAM_IP | grep -E "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5] |2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$"`
		if [ -z "$ipv4_flag" ];then
		    ipv6_flag=`echo $L_PARAM_IP | grep -E "^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9{1}]|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})(\.(25[0-5]|2[0-4][0-9]{1}|1[0-9]{1}[0-9]{1}|[1-9]?[0-9]{1})){3}))|:)))(%.+)?\s*$"`
	            if [ -z "$ipv6_flag" ];then
		        echo "input ip is not a invalid IPv4 or IPv6 address."
			continue
		    fi
		fi
		L_PARAM_Port=`echo "$G_CMD_PARAM" |awk '{print $3}'|grep -E "^[0-9]{1,5}$"`
		if [ -z "$L_PARAM_Port" ];then
		    echo "client_port_num must be an integer,range is 1~65535,please check your input."
		    continue
		else
		    if [ $L_PARAM_Port -le 65535 -a $L_PARAM_Port -ge 1 ];then
		        sudo $G_CMD_PARAM
		    else
		        echo "client_port_num must be an integer,range is 1~65535,please check your input."
		        continue
	            fi
		fi
		;;
		"df")
                L_PARAM_VAL=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                L_PARAM_NUM=`echo "$G_CMD_PARAM" | wc -w`
                if [ "${L_PARAM_VAL}" == "-h" -a ${L_PARAM_NUM} -eq 2 ];then
                    sudo df -h
                else
                    echo "The command \"${G_CMD_PARAM}\" is invalid. Run \"df -h\"."
                fi
                ;;
        "updatebios")
                BOARD_TYPE="`grep "^Product Name is" /proc/osp/bsp | awk '{print $4}'`"
                #只是Purly2U和3U/6U需要替换固件
                if [[ "$BOARD_TYPE" == PANGEA_V2R5C00  || "$BOARD_TYPE" == PANGEA_V2R5C00_2U ]] ; then
                    echo "DANGER: You are about to perform a danger command. The command will restart and update BIOS of this controller. You must run this command on each controller in sequence. You can run this command on other controllers only after confirming that the controller is restored. If you run this command on multiple controllers at the same time, data in the system memory will be lost."
                    echo "Suggestion: Before you perform this operation, make sure the operation will not affect working of system."
                    echo "Are you sure to restart and update BIOS of this controller?(y/n)"
                    read -p "" L_INPUT
                    if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                        if [ -f /startup_disk/conf/conf_local/V500R007C61SPH018BiosFlag ] ; then
                            echo "BIOS is updated no need to update again."	
                        else
                            touch -f /startup_disk/conf/conf_local/V500R007C61SPH018BiosFlag
                            if [ -f /startup_disk/conf/conf_local/V500R007C61SPH018ResumeBiosFlag ] ; then
                                rm -f /startup_disk/conf/conf_local/V500R007C61SPH018ResumeBiosFlag
                            fi
                            sync
                            sudo reboot -f
                        fi
                    fi
                else
                    echo "Borad type is $BOARD_TYPE no need to update BIOS."				
                fi
            ;;    
            
        "resumebios")
            BOOT_LINK=`ls -l /startup_disk/image | grep -a "boot ->" |awk '{print $11}'` 
            PANGEA_LINK=`ls -l /startup_disk/image/$BOOT_LINK/update_pkg | grep -i "PANGEA" |awk '{print $9}'`
            BOARD_TYPE="`grep "^Product Name is" /proc/osp/bsp | awk '{print $4}'`"
            #只是Purly2U和3U/6U需要替换固件
            if [[ "$BOARD_TYPE" == PANGEA_V2R5C00  || "$BOARD_TYPE" == PANGEA_V2R5C00_2U ]] ; then
                echo "DANGER: You are about to perform a danger command. The command will restart and resume BIOS of this controller. You must run this command on each controller in sequence. You can run this command on other controllers only after confirming that the controller is restored. If you run this command on multiple controllers at the same time, data in the system memory will be lost."
                echo "Suggestion: Before you perform this operation, make sure the operation will not affect working of system."
                echo "Are you sure to restart and resume BIOS of this controller?(y/n)"
                read -p "" L_INPUT
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                    if [ -f /startup_disk/conf/conf_local/V500R007C61SPH018BiosFlag ] ; then
                        if [ -f /startup_disk/image/$BOOT_LINK/update_pkg/$PANGEA_LINK/bios/bios_bak.ROM ] ; then
                            if [ -f /startup_disk/conf/conf_local/V500R007C61SPH018BiosFlag ]  ; then
                                rm -f /startup_disk/conf/conf_local/V500R007C61SPH018BiosFlag
                            fi
                            touch -f /startup_disk/conf/conf_local/V500R007C61SPH018ResumeBiosFlag
                            sync
                            sudo reboot -f
                        fi
                    else
                        echo "BIOS is origin no need to resume."
                    fi
                fi
            else
                echo "Borad type is $BOARD_TYPE no need to resume BIOS."					
            fi
            ;;
    "enableiocfw")
        echo "DANGER: You are about to perform a danger command. After executing this command, restart controller will update the firmware of all Hi1821 cards on this controller. You must run this command on each controller."
        echo "Suggestion: After you perform this operation, you must restart the device to take effect, but which will affect working of system."
        echo "Are you sure to update firmware of Hi1821 on this controller?(y/n)"
        read -p "" L_INPUT
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then
                        if [ -f /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag ] ; then
                            echo "[hi1821] ------The firmware is already update."	
                        else
                            if [ -f /startup_disk/conf/conf_local/ResumeiocFwFlagSPH050Flag ] ; then
                                rm -f /startup_disk/conf/conf_local/ResumeiocFwFlagSPH050Flag
                                if [ $? -ne 0 ]; then
                                    echo "[hi1821] ------rm /startup_disk/conf/conf_local/ResumeiocFwFlagSPH050Flag file failed."
                                    exit 0
                                fi
                            fi
                            
                            touch -f /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag
                            if [ $? -eq 0 ]; then
                                echo "[hi1821] ------The firmware upgrade of the Hi1821 card takes effect only after the controller is restarted, please reboot this controller."
                            else
                                echo "[hi1821] ------touch /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag file failed."
                            fi
                            sync
                        fi
                fi
                ;;    
    
        "disableiocfw")
        echo "DANGER: You are about to perform a danger command. After executing this command, restart controller will resume the firmware of all Hi1821 cards on this controller. You must run this command on each controller."
        echo "Suggestion: After you perform this operation, you must restart the device to take effect, but which will affect working of system."
        echo "Are you sure to resume firmware of Hi1821 cards on this controller?(y/n)"
        read -p "" L_INPUT        
                if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then               
                        if [ -f /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag ] ; then
                            rm -f /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag
                            if [ $? -eq 0 ]; then
                                touch -f /startup_disk/conf/conf_local/ResumeiocFwFlagSPH050Flag
                                if [ $? -eq 0 ]; then
                                    echo "[hi1821fw] ------The firmware resume of the Hi1821 card takes effect only after the controller is restarted, please reboot this controller."
                                else
                                    echo "[hi1821fw] ------touch /startup_disk/conf/conf_local/ResumeiocFwFlagSPH050Flag file failed."
                                fi
                                sync
                            else
                                echo "[hi1821fw] ------rm /startup_disk/conf/conf_local/UpdateiocFwFlagSPH050Flag file failed."
                            fi
                        else
                            echo "[hi1821fw] ------The firmware no need to resume."
                        fi
                fi
                ;;   
    "changeetherrorcoderule")
        echo "WARNING: You are about to change the bit error detection policy of eth port. This operation will change the original parameters for detecting bit errors on the port You must run this command on each controller."
        echo "Suggestion: Exercise caution when performing this operation."
        echo "Are you sure you really want to perform the operation?(y/n)"
        read -p "" L_INPUT        
            if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then  
                ETHERRORRULERET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 4) print 1; else print 0}'`
                if [ "$ETHERRORRULERET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                PERIOD=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                THRESHOLD=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                TIMES=`echo "$G_CMD_PARAM" | awk '{print $4}'`
                if [[ "$PERIOD" -lt "1" || "$PERIOD" -gt "65535" ]];then
                    echo "Input period parameter error!"
                    continue
                fi
                if [[ "$THRESHOLD" -lt "1" || "$THRESHOLD" -gt "65535" ]];then
                    echo "Input threshold parameter error!"
                    continue
                fi
                if [[ "$TIMES" -lt "1" || "$TIMES" -gt "65535" ]];then
                    echo "Input times parameter error!"
                    continue
                fi
                echo "Input parameter: period:$PERIOD, threshold: $THRESHOLD, times: $TIMES"
                echo -e "msc setethporterrorcoderule ${PERIOD} ${THRESHOLD} ${TIMES}\nexit\n" | diagnose --auto
            fi
        ;;
    "showetherrorcoderule")
        echo -e "msc getethporterrorcoderule\nexit\n" | diagnose --auto
        ;;

    "upgradesmm")
                bash +x /OSM/script/upgradesmmcpld.sh 0
                DMI_PRINT_RESULT $?
                ;;
    "rollbacksmm")
                bash +x /OSM/script/upgradesmmcpld.sh 1
                DMI_PRINT_RESULT $?
                ;;
    "checkupgradesmmversion")
                bash +x /OSM/script/upgradesmmcpld.sh 2
                DMI_PRINT_RESULT $?
                ;;
    "checkrollbacksmmversion")
                bash +x /OSM/script/upgradesmmcpld.sh 3
                DMI_PRINT_RESULT $?
                ;;
    "changememalarmpara")
        echo "WARNING: You are about to change the alarm policy of controller memory. This operation will change the original parameters for alarm on the controller."
        echo "Suggestion: Exercise caution when performing this operation."
        echo "Are you sure you really want to perform the operation?(y/n)"
        read -p "" L_INPUT        
            if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then  
                CHANGE_MEMORY_ALARM_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 10) print 1; else print 0}'`
                if [ "$CHANGE_MEMORY_ALARM_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                VALID_CHECK=`echo "$G_CMD_PARAM" | grep -E "^changememalarmpara\s([0-9]{1,4}\s){8}([0-9]{1,4})$"`
                if [ -z "$VALID_CHECK" ];then
                    echo "Input parameter is err, please check your input."
                    continue
                fi
                MUILT_ADDR_NUMBER=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                MUILT_ADDR_DURATION=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                MUILT_BANK_DURATION=`echo "$G_CMD_PARAM" | awk '{print $4}'`
                MUILT_DIMM_DURATION=`echo "$G_CMD_PARAM" | awk '{print $5}'`
                WINDOW_SIZE=`echo "$G_CMD_PARAM" | awk '{print $6}'`
                WINDOW_DURATION=`echo "$G_CMD_PARAM" | awk '{print $7}'`
                WINDOW_ERROR=`echo "$G_CMD_PARAM" | awk '{print $8}'`
                CE_STORM_DURATION=`echo "$G_CMD_PARAM" | awk '{print $9}'`
                CE_STORM_ERROR=`echo "$G_CMD_PARAM" | awk '{print $10}'`
                if [[ "$MUILT_ADDR_NUMBER" -lt "1" || "$MUILT_ADDR_NUMBER" -gt "500" ]];then
                    echo "Input number of memory multi-address solid failure parameter error!"
                    continue
                fi
                if [[ "$MUILT_ADDR_DURATION" -lt "0" || "$MUILT_ADDR_DURATION" -gt "1001" ]];then
                    echo "Input days of memory multi-address solid failure parameter error!"
                    continue
                fi
                if [[ "$MUILT_BANK_DURATION" -lt "0" || "$MUILT_BANK_DURATION" -gt "1001" ]];then
                    echo "Input days of memory multi-bank error parameter error!"
                    continue
                fi
                if [[ "$MUILT_DIMM_DURATION" -lt "0" || "$MUILT_DIMM_DURATION" -gt "1001" ]];then
                    echo "Input days of multi-dimm error parameter error!"
                    continue
                fi
                if [[ "$WINDOW_SIZE" -lt "0" || "$WINDOW_SIZE" -gt "1001" ]];then
                    echo "Input days range of memory long time error parameter error!"
                    continue
                fi
                if [[ "$WINDOW_DURATION" -lt "1" || "$WINDOW_DURATION" -gt "1000" ]];then
                    echo "Input days of memory long time error parameter error!"
                    continue
                fi
                if [[ "$WINDOW_ERROR" -lt "1" || "$WINDOW_ERROR" -gt "1000" ]];then
                    echo "Input number of memory error per day parameter error!"
                    continue
                fi
                if [[ "$CE_STORM_DURATION" -lt "0" || "$CE_STORM_DURATION" -gt "1001" ]];then
                    echo "Input hours of memory ce storm parameter error!"
                    continue
                fi
                if [[ "$CE_STORM_ERROR" -lt "1" || "$CE_STORM_ERROR" -gt "1000" ]];then
                    echo "Input number of memory ce per hour parameter error!"
                    continue
                fi
                ITEM_INFO="$MUILT_ADDR_NUMBER,$MUILT_ADDR_DURATION,$MUILT_BANK_DURATION,$MUILT_DIMM_DURATION,$WINDOW_SIZE,$WINDOW_DURATION,$WINDOW_ERROR,$CE_STORM_DURATION,$CE_STORM_ERROR"
                result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK PowerType $ITEM_INFO\nexit\n" | diagnose --auto |grep Success`
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Change memory alarm parameter Fail, Please Retry."
                else
                    echo "Status: Success."
                    echo "Input parameter:"
                    echo "Number of memory multi-address solid failure: $MUILT_ADDR_NUMBER"
                    echo "Days of memory multi-address solid failure: $MUILT_ADDR_DURATION"
                    echo "Days of memory multi-bank error: $MUILT_BANK_DURATION "
                    echo "Days of multi-dimm error: $MUILT_DIMM_DURATION "
                    echo "Days range of memory long time error: $WINDOW_SIZE "
                    echo "Days of memory long time error: $WINDOW_DURATION "
                    echo "Number of memory error per day: $WINDOW_ERROR "
                    echo "Hours of memory ce storm: $CE_STORM_DURATION "
                    echo "Number of memory ce per hour: $CE_STORM_ERROR "
                    echo "Detail: Change memory alarm parameter: $result."
                    OS_echo "Change memory alarm parameter: $result."
                fi
            fi
        ;;
    "showmemalarmpara")
        MUILT_ADDR_NUMBER=20
        MUILT_ADDR_DURATION=30
        MUILT_BANK_DURATION=30
        MUILT_DIMM_DURATION=30
        WINDOW_SIZE=30
        WINDOW_DURATION=15
        WINDOW_ERROR=20
        CE_STORM_DURATION=48
        CE_STORM_ERROR=30
        showmemalarmpararet=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 1) print 1; else print 0}'`
        if [ "$showmemalarmpararet" -ne "0" ];then
            echo "Status: Fail."
            echo "Detail: Input parameter number error! Try 'help' for more information."
            continue
        fi
        
        MEMORY_ALARM_VALUE=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK PowerType 1\nexit\n" | diagnose --auto |awk -F= '/PowerType=/{print $2}'`

        NUMBER=$(echo ${#MEMORY_ALARM_VALUE})
        if [ $NUMBER -eq 0 ]; then
            echo "Status: Fail."
            echo "Detail: Show memory alarm parameter Fail, Please Retry."
            continue	
        fi
        if [ $NUMBER -ge 8 ]; then
            MUILT_ADDR_NUMBER=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $1}')
            MUILT_ADDR_DURATION=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $2}')
            MUILT_BANK_DURATION=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $3}')
            MUILT_DIMM_DURATION=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $4}')
            WINDOW_SIZE=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $5}')
            WINDOW_DURATION=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $6}')
            WINDOW_ERROR=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $7}')
            CE_STORM_DURATION=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $8}') 
            CE_STORM_ERROR=$(echo $MEMORY_ALARM_VALUE | awk -F, '{print $9}') 
        fi
        echo "Number of memory multi-address solid failure: $MUILT_ADDR_NUMBER"
        echo "Days of memory multi-address solid failure: $MUILT_ADDR_DURATION"
        echo "Days of memory multi-bank error: $MUILT_BANK_DURATION"
        echo "Days of multi-dimm error: $MUILT_DIMM_DURATION"
        echo "Days range of memory long time error: $WINDOW_SIZE"
        echo "Days of memory long time error: $WINDOW_DURATION"
        echo "Number of memory error per day: $WINDOW_ERROR"
        echo "Hours of memory ce storm: $CE_STORM_DURATION"
        echo "Number of memory ce per hour: $CE_STORM_ERROR"
        ;;
    "setnumaswitch")
        BOARD_TYPE="`grep "^Product Name is" /proc/osp/bsp | awk '{print $4}'`"
        if [ "$BOARD_TYPE" == PANGEA_V2R5C00 ] ; then
            echo "DANGER: You are about to perform a danger command. The command will set numa switch of this controller. You must run this command on each controller in sequence. You can run this command on other controllers only after confirming that the controller is restored. If you run this command on multiple controllers at the same time, data in the system memory will be lost."
            echo "Suggestion: Before you perform this operation, make sure the operation will not affect working of system."
            echo "Are you sure to restart and set numa switch of this controller?(y/n)"
            read -p "" L_INPUT
            if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ];then
                setret=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 2) print 1; else print 0}'`
                if [ "$setret" -ne "0" ];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter number error! Try 'help' for more information."
                    continue
                fi
                numaswitch=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                echo "Detail: Input Switch Parameter are: $numaswitch."
                if [[ "$numaswitch" -ne "0" && "$numaswitch" -ne "1" ]];then
                    echo "Status: Fail."
                    echo "Detail: Input parameter error! switch must be 0 or 1."
                    continue
                fi
                getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                if [ $? != 0 ]; then 
                    getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                fi
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Switch numa fail, please contact the technical engineer."
                    continue
                fi
                #如果设置和查询的一样，则不需要设置下去。     
                if [ "$getnumaswitch" == "$numaswitch" ]; then 
                    echo "Status: Success."
                    echo "Detail: The current numa switch:$getnumaswitch and set numa switch:$numaswitch is same, no need to reboot the controller."        
                    continue
                fi
                
                #调用命令ipmitool raw 0x32 0xb5 0 2 0 0 0x69 1/0开关NUMA
                result=(`sudo ipmitool raw 0x32 0xb5 0 2 0 0 0x69 ${numaswitch}`)
                if [ $? != 0 ]; then 
                    result=(`sudo ipmitool raw 0x32 0xb5 0 2 0 0 0x69 ${numaswitch}`)
                fi
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Switch numa fail, please contact the technical engineer."
                    continue
                fi
                #调用命令ipmitool raw 0x32 0xb4 0 2 0 0 0x69查询NUMA开关状态
                getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                if [ $? != 0 ]; then 
                    getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                fi
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Switch numa fail, please contact the technical engineer."
                    continue
                fi
                
                if [ "$getnumaswitch" == "$numaswitch" ]; then 
                    echo "Status: Success."
                    echo "Detail: Switch numa $numaswitch success."
                    if [ "$numaswitch" == "1" ]; then
                        touch -f /startup_disk/conf/conf_local/V500R007C61SPH018NumaFlag
                    elif [ "$numaswitch" == "0" ]; then
                        rm -f /startup_disk/conf/conf_local/V500R007C61SPH018NumaFlag
                    fi
                    sync
                    sudo reboot -f
                else
                    echo "Status: Fail."
                    echo "Detail: Switch numa fail, please contact the technical engineer."
                fi
            fi
        else
            echo "Board type is $BOARD_TYPE no support to switch numa."					
        fi
        ;;
    "shownumaswitch")
            BOARD_TYPE="`grep "^Product Name is" /proc/osp/bsp | awk '{print $4}'`"
            if [ "$BOARD_TYPE" == PANGEA_V2R5C00 ] ; then
                #调用命令ipmitool raw 0x32 0xb4 0 2 0 0 0x69查询NUMA开关状态
                getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                if [ $? != 0 ]; then 
                    getnumaswitch=$((`sudo ipmitool raw 0x32 0xb4 0 2 0 0 0x69`))
                fi
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Switch numa fail, please contact the technical engineer."
                else
                    echo "Status: Success."
                    echo "Detail: Current numa switch is: $getnumaswitch."
                    OS_echo "Current Numa switch is: $getnumaswitch."
                fi
            else
                echo "Board type is $BOARD_TYPE no support to switch numa."
            fi
        ;;

    "bpi2crepair")
        BOARD_TYPE="`grep "^Product Name is" /proc/osp/bsp | awk '{print $4}'`"
        FRAME_MODEL="`grep "^Frame Model is" /proc/osp/bsp | awk '{print $4}'`"
        #限定V3V5 3U执行
        if [[ "$BOARD_TYPE" == PANGEA_V2R5C00 || "$BOARD_TYPE" == PANGEA_V2R1C01 ]] ; then
            if [[ "$FRAME_MODEL" == "3U" ]] ; then 
                echo "Repairing..."
                FLG=0;
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=100;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=110;
                fi
                sleep 1;
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=101;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=111;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=200;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=210;
                fi
                sleep 1;
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=201;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0x22 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=211;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0xd0 0x1 0x0 0x0 0x6 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=300;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0xd0 0x1 0x0 0x0 0x6 0x0 0x0 0x0 0x1 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=310;
                fi
                sleep 1;
                result=(`sudo ipmitool raw 0x32 0x71 0x0 0x04 0x0 0x0 0x92 0xd0 0x1 0x0 0x0 0x6 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=301;
                fi
                result=(`sudo ipmitool raw 0x32 0x71 0x1 0x04 0x0 0x0 0x92 0xd0 0x1 0x0 0x0 0x6 0x0 0x0 0x0 0x0 0x0 0x0 0x0`)
                if [ $? != 0 ]; then 
                    FLG=311;
                fi
                if [ "$FLG" == "0" ];then
                    echo "Status: Success."
                else
                    echo "Status: Fail."
                    echo "Detail: $FLG."
                fi
            else
                echo "This device does not support the backplane I2C components repair function."
                echo "The bpi2crepair command is only for V3V5 3U products."
            fi
        else
            echo "This device does not support the backplane I2C components repair function."
            echo "The bpi2crepair command is only for V3V5 3U products."
        fi
        ;;
    "setdimmrule")
        echo "WARNING: You are about to set the dimm rule of controller memory. This operation will change the original parameters for alarm on the controller."
        echo "Suggestion: Exercise caution when performing this operation."
        echo "Are you sure you really want to perform the operation?(y/n)"
        read -p "" L_INPUT        
        if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then  
            SET_DIMM_PARA_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 5) print 1; else print 0}'`
            if [ "$SET_DIMM_PARA_RET" -ne "0" ];then
                echo "Input parameter number error!"
                echo "Try 'help' for more information."
                continue
            fi
            DIMM_VENDOR=`echo "$G_CMD_PARAM" | awk '{print $2}' | grep -E "^0x[0-9A-Fa-f]{1,4}$"`
            if [ -z "$DIMM_VENDOR" ];then
                echo "Vendor id err, please check your input."
                continue
            fi
            DIMM_PRODUCT_TYPE=`echo "$G_CMD_PARAM" | awk '{print $3}' | grep -E "^(\S{1,20}:){0,7}\S{1,20}$"`
            if [ -z "$DIMM_PRODUCT_TYPE" ];then
                echo "Product type err, please check your input."
                continue
            fi
            DIMM_BATCH=`echo "$G_CMD_PARAM" | awk '{print $4}' | grep -E "^[0-9]{4}-[0-9]{4}$"`
            if [ -z "$DIMM_BATCH" ];then
                echo "Batch err, please check your input."
                continue
            fi
            DIMM_SUPORT_RULE=`echo "$G_CMD_PARAM" | awk '{print $5}' | grep -E "^([1-6]-){0,5}[1-6]$"`
            if [ -z "$DIMM_SUPORT_RULE" ];then
                echo "Rule err, please check your input."
                continue
            fi
            DIMM_RULE_ITEM=("fan_0_name" "fan_1_name" "fan_2_name" "fan_3_name" "power_0_name" "power_1_name" "power_2_name" "power_3_name")
            ITEM_INFO="DIMM:$DIMM_VENDOR,$DIMM_PRODUCT_TYPE,$DIMM_BATCH,$DIMM_SUPORT_RULE"
            IS_REPETE_ITEM=0
            IS_UPDATE_ITEM=0

            for ITEM in ${DIMM_RULE_ITEM[@]}
            do
                ITEM_TMP=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK $ITEM 1\nexit\n" | diagnose --auto | awk -F= '/=/{print $2}'`
                if [ "${ITEM_INFO}" = "${ITEM_TMP}" ];then
                    IS_REPETE_ITEM=1
                    break
                fi

                if [ "${ITEM_INFO%','*}" = "${ITEM_TMP%','*}" ];then
                    IS_UPDATE_ITEM=1
                    UPDATE_ITEM=$ITEM
                    break
                fi
            done
            if [ $IS_REPETE_ITEM != 0 ];then
                echo "Rule repeats, please check your input."
                continue
            fi
                
            if [ $IS_UPDATE_ITEM != 0 ];then
                echo "Update rule."
                result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK $UPDATE_ITEM $ITEM_INFO\nexit\n" | diagnose --auto |grep Success`
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Change memory alarm parameter Fail, Please Retry."
                else
                    echo "Status: Success."
                    echo "Input parameter:"
                    echo "Vendor id: $DIMM_VENDOR"
                    echo "Product type: $DIMM_PRODUCT_TYPE"
                    echo "Pach: $DIMM_BATCH"
                    echo "Suport rule: $DIMM_SUPORT_RULE"
                    OS_echo "Update dimm rule: $result."
                fi
                continue
            fi
            CONFIG_RESULT=0
            for ITEM in ${DIMM_RULE_ITEM[@]}
            do
                #查找一个空的项
                VALID=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK $ITEM 1\nexit\n" | diagnose --auto | grep DIMM`
                if [ $? != 0 ];then
                    result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK $ITEM $ITEM_INFO\nexit\n" | diagnose --auto |grep Success`
                    if [ $? != 0 ]; then 
                        echo "Status: Fail."
                        echo "Detail: Change dimm rule parameter Fail, Please Retry."
                    else
                        echo "Status: Success."
                        echo "Input parameter:"
                        echo "Vendor id: $DIMM_VENDOR"
                        echo "Product type: $DIMM_PRODUCT_TYPE"
                        echo "Pach: $DIMM_BATCH"
                        echo "Suport rule: $DIMM_SUPORT_RULE"
                        OS_echo "Change dimm rule: $result."
                    fi
		    CONFIG_RESULT=1
                    break
                fi
            done
                
            if [ $CONFIG_RESULT != 1 ];then
                echo "Status: Fail."
                echo "Detail: No Unused config item."
                OS_echo "Set dimm rule failed, item is full."
            fi
        fi
        ;;
        "showdimmrule")
            DIMM_RULE0=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK fan_0_name 1\nexit\n" | diagnose --auto |awk -F= '/fan_0_name=/{print $2}' | grep DIMM`
            DIMM_RULE1=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK fan_1_name 1\nexit\n" | diagnose --auto |awk -F= '/fan_1_name=/{print $2}' | grep DIMM`
            DIMM_RULE2=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK fan_2_name 1\nexit\n" | diagnose --auto |awk -F= '/fan_2_name=/{print $2}' | grep DIMM`
            DIMM_RULE3=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK fan_3_name 1\nexit\n" | diagnose --auto |awk -F= '/fan_3_name=/{print $2}' | grep DIMM`
            DIMM_RULE4=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK power_0_name 1\nexit\n" | diagnose --auto |awk -F= '/power_0_name=/{print $2}' | grep DIMM`
            DIMM_RULE5=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK power_1_name 1\nexit\n" | diagnose --auto |awk -F= '/power_1_name=/{print $2}' | grep DIMM`
            DIMM_RULE6=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK power_2_name 1\nexit\n" | diagnose --auto |awk -F= '/power_2_name=/{print $2}' | grep DIMM`
            DIMM_RULE7=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK power_3_name 1\nexit\n" | diagnose --auto |awk -F= '/power_3_name=/{print $2}' | grep DIMM`

            echo "Rule 0: ${DIMM_RULE0//','/ }"
            echo "Rule 1: ${DIMM_RULE1//','/ }"
            echo "Rule 2: ${DIMM_RULE2//','/ }"
            echo "Rule 3: ${DIMM_RULE3//','/ }"
            echo "Rule 4: ${DIMM_RULE4//','/ }"
            echo "Rule 5: ${DIMM_RULE5//','/ }"
            echo "Rule 6: ${DIMM_RULE6//','/ }"
            echo "Rule 7: ${DIMM_RULE7//','/ }"

            ;;
        "deldimmrule")
            echo "WARNING: You are about to delete the dimm rule of controller memory. This operation will del the dimm rule for alarm on the controller."
            echo "Suggestion: Exercise caution when performing this operation."
            echo "Are you sure you really want to perform the operation?(y/n)"
            read -p "" L_INPUT        
            if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then  
                DEL_DIMM_PARA_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 2) print 1; else print 0}'`
                if [ "$DEL_DIMM_PARA_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi
                DEL_ID=`echo "$G_CMD_PARAM" | awk '{print $2}' | grep -E "^[0-7]{1}$"`
                if [ -z "$DEL_ID" ];then
                    echo "Delete id is error, please check your input."
                    continue
                fi
                DIMM_RULE_ITEM=("fan_0_name" "fan_1_name" "fan_2_name" "fan_3_name" "power_0_name" "power_1_name" "power_2_name" "power_3_name")
                result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK ${DIMM_RULE_ITEM[$DEL_ID]} "unused"\nexit\n" | diagnose --auto |grep Success`
                if [ $? != 0 ]; then 
                    echo "Status: Fail."
                    echo "Detail: Delete dimm rule failed, Please Retry."
                else
                    echo "Delete dimm rule: $result."
                fi
            fi
            ;;
        "setrepairthrd")
            echo "WARNING: You are about to change the repair threshold of interface card. If the threshold is exceeded, the interface card will be powered off and links may not be redundant."
            echo "Are you sure you really want to perform the operation?(y/n)"
            read -p "" L_INPUT        
            if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then  
                DEL_DIMM_PARA_RET=`echo "$G_CMD_PARAM" | awk 'END{if(NF != 4) print 1; else print 0}'`
                if [ "$DEL_DIMM_PARA_RET" -ne "0" ];then
                    echo "Input parameter number error!"
                    echo "Try 'help' for more information."
                    continue
                fi

                VALID_CHECK=`echo "$G_CMD_PARAM" | grep -E "^setrepairthrd\s[0-9]\s[0-9]{1,2}\s[0-9]{1,2}$"`
                if [ -z "$VALID_CHECK" ];then
                    echo "Input parameter is err, please check your input."
                    continue
                fi
                CARD_TYPE=`echo "$G_CMD_PARAM" | awk '{print $2}'`
                RAPAIR_TIME_THRD=`echo "$G_CMD_PARAM" | awk '{print $3}'`
                RAPAIR_CNT_THRD=`echo "$G_CMD_PARAM" | awk '{print $4}'`
                if [[ "$CARD_TYPE" -lt "0" || "$CARD_TYPE" -gt "1" ]];then
                    echo "Input card type parameter error!"
                    continue
                fi
				
                if [[ "$RAPAIR_TIME_THRD" -lt "0" || "$RAPAIR_TIME_THRD" -gt "24" ]];then
                    echo "Input repair time threshold parameter error!"
                    continue
                fi
				
                if [[ "$RAPAIR_CNT_THRD" -lt "0" || "$RAPAIR_CNT_THRD" -gt "15" ]];then
                    echo "Input repair count threshold parameter error!"
                    continue
                fi

                INSERTSTR="AerThrd:$RAPAIR_TIME_THRD,$RAPAIR_CNT_THRD"
                if [ "${CARD_TYPE}" == "0" ];then	
                        result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK MaxDiskNum $INSERTSTR\nexit\n" | diagnose --auto |grep Success`
                        if [ $? != 0 ]; then 
                            echo "Status: Fail."
                            echo "Detail: Set repair threshold failed, Please Retry."
                        else
                            echo "Set front-end card repair threshold: $result."
                        fi
                else
                        result=`echo -e "econf renewcfg FRAME_EXP_FC_4U_24DISK MaxPowerNumPerFrame $INSERTSTR\nexit\n" | diagnose --auto |grep Success`
                        if [ $? != 0 ]; then 
                            echo "Status: Fail."
                            echo "Detail: Set repair threshold failed, Please Retry."
                        else
                            echo "Set back-end card repair threshold: $result."
                        fi
                fi
            fi
                ;;
            "showrepairthrd")
                FRONTEND=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK MaxDiskNum 1\nexit\n" | diagnose --auto |awk -F= '/MaxDiskNum=/{print $2}' | grep AerThrd`
                BACKEND=`echo -e "econf getcfg FRAME_EXP_FC_4U_24DISK MaxPowerNumPerFrame 1\nexit\n" | diagnose --auto |awk -F= '/MaxPowerNumPerFrame=/{print $2}' | grep AerThrd`
                if [ -n "$FRONTEND" ]; then
                    echo "Front-end card threshold:${FRONTEND#*AerThrd:}"
                else
                    echo "Front-end card threshold:8,5"
                fi
                if [ -n "$BACKEND" ]; then
                    echo "Back-end card threshold:${BACKEND#*AerThrd:}"
                else
                    echo "Back-end card threshold:8,5"
                fi
                ;;
	    
            "")
                ;;
             *)
                L_PWD=`pwd`
                # 检查命令合法性
                OS_CHECK_CMD_VALID
                if [ "$?" != 0 ];then
                    cd ${L_PWD} &>/dev/null
                    continue
                fi       

                
                # 高危命令执行提示
                OS_ALARM_CMD_EMERGENCY
                if [ $? -ne 0 ]; then
                    echo "DANGER: You are going to perform a danger command."
                    echo "Suggestion: Before you perform this operation, make sure the operation will not affect working of system."
                    echo "Have you read danger alert message carefully?(y/n)"
                    read -p "" L_INPUT
                    if [ "${L_INPUT}" == "y" -o "${L_INPUT}" == "Y" ]; then
                        echo "Are you sure you really want to perform the operation?(y/n)"
                        read -p "" L_INPUT
                        if [ "${L_INPUT}" != "y" -a "${L_INPUT}" != "Y" ]; then
                            cd ${L_PWD} &>/dev/null
                            continue
                        fi
                    else
                        cd ${L_PWD} &>/dev/null
                        continue
                    fi
                fi
               
                #白名单防呆处理，增加验证码输入与高危提示
                CLI_VERIFICATION_AND_DANGER
                if [ $? -ne 1 ]; then
                  cd ${L_PWD} &>/dev/null
                  continue
                fi
          
                #执行命令
                OS_EXECUTE_DEBUG_CMD
                if [ "$?" != 0 ];then
                    cd ${L_PWD} &>/dev/null
                    continue
                fi
                ;;
    esac
done

exit 0


