今天服务器因为配置文件出错,导致玩家数据异常,因此需要对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"