Shell综合查询各个游戏服务器的数据
今天服务器因为配置文件出错,导致玩家数据异常,因此需要对50多个服务器,每个服务器10个表的数据进行查询。
因此在一台服务器上写了下面的这段Shell脚本,
- #!/bin/sh
- CONF='servers.conf'
- SERV_LIST=$(cat $CONF | grep -v ^# | grep show_flag | grep = | awk -F= '{printf "%s ",$1}')
- for servInfo in $(cat $CONF | grep -v ^# | grep show_flag | grep =)
- do
- # TTT=$(echo $servInfo | awk -F= '{printf "%s : %s",$1, $2}')
- TTT=$(echo $servInfo)
- FILE_PATH='/data/tmp/lottery'
- DATA_FILE=$FILE_PATH'/'$(echo $TTT | awk -F= '{printf "%s", $1}')
- mkdir -p $FILE_PATH
- DB_HOST=$(echo $TTT | awk -F: '{printf "%s", $3}')
- DB_NAME=$(echo $TTT | awk -F: '{printf "%s", $4}')
- DB_PORT=$(echo $TTT | awk -F: '{printf "%s", $5}' | sed 's/"//g')
- DB_TABLES='Operation_log_1 Operation_log_2 Operation_log_3 Operation_log_4 Operation_log_5 Operation_log_6 Operation_log_7 Operation_log_8 Operation_log_9 Operation_log_10'
- for table in $DB_TABLES
- do
- echo 'HOST:'$DB_HOST', PORT:'$DB_PORT', NAME:'$DB_NAME', TABLE:'$table
- $(mysql -uslj -pCZH*CcUu4lHKptk -h$DB_HOST -P${DB_PORT} ${DB_NAME} -e 'select playerId, count(playerId) as n from '$table' where actiontime >= "2012-03-11 00:00:00" group by playerId order by n desc' >> $DATA_FILE)
- done
- done
注:servers.conf
里面保存的是数据库服务器的信息,数据格式如下:db1_tencent="show_flag:1:IP1:数据库名1:端口1"
db2_tencent="show_flag:1:IP2:数据库名2:端口2"
db3_tencent="show_flag:1:IP3:数据库名3:端口3"
db4_tencent="show_flag:1:IP4:数据库名4:端口4"
相关推荐
86103155 2019-12-23
huangzonggui 2019-11-17
zhangzhicheng 2007-12-19
zhangzhicheng 2007-11-01
Congpanpan 2007-10-03
TIGERXC 2019-11-04
amorfait 2009-01-30
wq0 2019-10-23
lsn0LSN 2017-08-07
阿赞 2015-02-04
小菜鸟 2012-09-03
huangzonggui 2015-03-23
liboxue 2010-01-31
sxlongwork 2010-01-29
dantesite 2010-01-15
dantesite 2019-07-01
mitesi 2013-06-14
红雪中国 2012-03-02