#!/bin/bash #修改mysql schema mycat_schema_file=/opt/mycat/conf/schema.xml cp $mycat_schema_file ${mycat_schema_file}.bak database_list='message xuejie' #找到usercenter的行号,由于schema成对出现有可能换行,在其上一行增加schema更可靠 last_schema_row_number=`sed -n '/<schema name="usercenter"/=' $mycat_schema_file` if [ ! -z "$last_schema_row_number" ]; then last_schema_row_number=`expr ${last_schema_row_number} - 1` for database in $database_list do new_schema_row_number=`sed -n "/<schema name=\"$database\"/=" $mycat_schema_file` if [ -z "$new_schema_row_number" ]; then shell_cmd='<schema name="'${database}'" checkSQLschema="false" sqlMaxLimit="20000" dataNode="'${database}'"></schema>' sed -i "${last_schema_row_number}a ${shell_cmd}" $mycat_schema_file last_schema_row_number=`expr ${last_schema_row_number} + 1` sed -i "${last_schema_row_number}s/^/ /g" $mycat_schema_file fi done fi #找到usercenter的行号,在下面增加dataNode last_node_row_number=`sed -n '/database="usercenter"/=' $mycat_schema_file` if [ ! -z "$last_node_row_number" ]; then for database in $database_list do new_node_row_number=`sed -n "/database=\"$database\"/=" $mycat_schema_file` if [ -z "$new_node_row_number" ]; then shell_cmd='<dataNode name="'$database'" dataHost="localhost1" database="'$database'" />' sed -i "${last_node_row_number}a ${shell_cmd}" $mycat_schema_file last_node_row_number=`expr ${last_node_row_number} + 1` sed -i "${last_node_row_number}s/^/ /g" $mycat_schema_file fi done fi
标签:last,配置文件,number,mycat,file,schema,节点,row From: https://www.cnblogs.com/xuejie/p/17318769.html