Skip to content

Instantly share code, notes, and snippets.

@Buttonwood
Created November 26, 2014 07:23
Show Gist options
  • Select an option

  • Save Buttonwood/6c68080ec201972aabb8 to your computer and use it in GitHub Desktop.

Select an option

Save Buttonwood/6c68080ec201972aabb8 to your computer and use it in GitHub Desktop.
A shell script for auto add sql to cobar
### corbar 添加查看表
#!/bin/bash
if [ $# != 3 ]; then
echo "Usage: sh $0 old.sql table_num table_name|sh"
echo "Example: sh job.sh old.sql 8 docdb"
echo " old.sh: 每张表要添加的sql语句"
echo " table_num: 每个ip有多少张表 [8]"
echo " table_name: 每张表的名字 [docdb]"
exit
fi
sql=$1
table_num=$2||8 #每个主机上见表的数目
table_name=$3||"testdb"
j=0
# your ip list here; 如果ip不同 需要修改
for i in `seq 1 32` ;do
j=$(( $j + 1 ))
if [[ -f $j.sql ]]; then
`rm -rf ${j}.sql`
fi
`touch ${j}.sql`
for (( k = (j - 1) * table_num + 1; k <= ( j * table_num ); k++ )) ;do
#echo $k
new_id=""
if [ $k -lt 10 ];then
new_id="00$k"
elif [ $k -lt 100 ];then
new_id="0$k"
else
new_id="$k"
fi
echo "use $table_name$new_id;" >>$j.sql
`cat $sql >>$j.sql`
echo "" >> $j.sql
done
host="192.168.1.$i"
echo "mysql -uroot -h $host -p <$j.sql" # cobar 结点远程操作mysql,执行新语句
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment