shell拉取MYSQL数据库数据

#!/bin/bash  
:<<!
被注释的多行内容
!
:<<!
##arr_db_table=([0, 12, "10.30.16.x"], [13, 24, "10.30.a.b"])
##arr_db_table=(1 2 3)
arr_db_table=((0 12 "10.30.16.x"), (13 24 "10.30.a.b"))
for var in ${arr_db_table[@]};
do
        echo $var
done
!
##cmd="select userid, type, value from game_db_00.attr_table_00 where type=121462 and value > 7"  
##cnt=$(mysql -h10.30.16.237 -uxx -pc@@@# -s -e "${cmd}")  
##echo "Current count is : ${cnt}"  
##exit 
:<<!
sites=("www.a.com www.b.com www.c.com www.d.com" "www.e.cn www.f.cn")  
n_sites=${#sites[*]}     #获取一维sites的数组长度  
for ((i=0;i<$n_sites;i++));  
do  
  inner_sites=(${sites[$i]}) #将一维sites字符串赋值到数组
  n_inner_sites=${#inner_sites[*]} #获取二位sites的数组长度  
  for ((j=0;j<$n_inner_sites;j++));  
  do  
    echo ${inner_sites[$j]}  #»ØÏÔsite  
    #do something  
  done  
done 
!
arr_db_table=("0 12 \"10.30.16.237\""    "13 24 \"10.30.16.x\""  "25 37 \"10.30.16.x\""   )
arr_db_table=("0 12 10.30.16.237"    "13 24 10.30.16.x"  "25 37 10.30.16.x"   )
db_num=${#arr_db_table[*]}
echo $db_num
for ((i=0; i<$db_num; i++));
do 
        db_info=(${arr_db_table[$i]})
        arg_num=(${#db_info[*]})
        echo "arg_num:$arg_num"
        game_db_begin=${db_info[0]}
        game_db_end=${db_info[1]}
        game_db_ip=${db_info[2]}
        echo "begin:$game_db_begin"
        echo "end:$game_db_end"
        echo "game_db_ip:$game_db_ip"
        for ((db_id=$game_db_begin; db_id <= $game_db_end; db_id++));
        do
                format_db_id=`printf "%02d" $db_id`
                db_name="game_db_$format_db_id"
                for ((tb_id=0; tb_id<=99; tb_id++));
                do
                        format_tb_id=`printf "%02d" $tb_id`
                        tb_name="attr_table_$format_tb_id"
                        db_tb_name="$db_name.$tb_name"
                        ##echo "db_table_name:$db_tb_name"
                        user="c"
                        pass="cps"
                        cmd="select userid, type, value from $tb_name where type=121462 and value>7"
                        result=`mysql -h$game_db_ip -u$user -p$pass -D $db_name -e "${cmd}"`
                        ##echo "db_host:$game_db_ip"
                        echo $result
                done
                ##echo "db_name:$db_name" 
        done
        ##:<<!
        for ((j=0; j<$arg_num; j++));
        do 
                echo ${db_info[$j]}
        done
        ##!
done
echo "hello hello hello"
num=0
format_num=`printf "%02d" $num`
echo "format_num:$format_num"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值