CheckIPAddress()
{
        echo $1 |grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" > /dev/ null
         if [ $? = 1 ];     then
                 return 1
         else
                a=`echo $1 | awk -F. '{print $1}'`
                b=`echo $1 | awk -F. '{print $2}'`
                c=`echo $1 | awk -F. '{print $3}'`
                d=`echo $1 | awk -F. '{print $4}'`
                #echo $a $b $c $d

                 for loop in $a $b $c $d
                do
                         if [ $loop -ge 255 ] || [ $loop -lt 0 ]; then
                                 return 2
                        fi
                done
        fi    

}


ConfigureDefaultRegion() {
    echo "Please input Region ip"
    ret=1
     while [ $ret != 0 ]
    do
     read region_ip
     CheckIPAddress $region_ip
     ret=$?
     #echo $ret
     if [ $ret = 1 ]; then
        echo "Wrong IP address, please reinput Region IP:"
     fi
    done
    /usr/bin/mysql -u root realworx_production -e " update regions set ip= '$region_ip' where id=1" 1>/dev/ null 2>/dev/ null
     if [ $? = 0 ]; then
                    /usr/bin/mysql -u root realworx_production -e " update config_params set val=1 where ident=55" 1>/dev/ null 2>/dev/ null
                    echo " set '$region_ip' as Default and Admin Region IP"
     else
                    val=`/usr/bin/mysql -u root realworx_production -e " select id from regions where ip= '$region_ip'" | awk '{if ($1 != "id") print $1}'`
                    /usr/bin/mysql -u root realworx_production -e " update config_params set val= '$val' where ident=55" 1>/dev/ null 2>/dev/ null
                    region_name=`/usr/bin/mysql -u root realworx_production -e " select name from regions where ip= '$region_ip'" | awk '{if ($1 != "name") print $1}'`
                    echo "IP already exists. So set '$region_name' as Admin Region. "
    fi
    echo "Region Setting Successfull."
}


#shell mysql

****************************************

#!/bin/bash

olname=erik ##旧值,也就是要替换掉的值

nwname=erik ##新值,也就是要替换为的值

domain=@set-china.net ##后缀,此处是用来操作邮件的,其它用途可以不要或替换成其它

mysql -u root -p password <
##操作数据库的开始,此处输入用户名及密码,<
##<
use extmail;

show tables;

update alias set goto=REPLACE(goto,'$olname','$nwname$domain');

EOF

exit 0;

****************************************

##语句少的情况下可以如下使用

#!/bin/bash

mysql -u root -p password -e "use mysql;select * from user(SQL语句)";

exit 0;

****************************************