标签:example 服务器 master linux export
先实现服务器的root ssh互信,在master服务器做如下操作
一、配置mysql服务器ip列表如下,可自定义:
ceshi1 192.168.177.73 3358
ceshi2 192.168.177.73 3359
二、#linux批量连接多服务器的shell脚本如下:
#!/bin/bash
if [[ "$#" -lt "5" ]]
then
echo "error"
echo "for example:$0 dbip.ini run.sql user pass db_name"
exit 1
fi
name=(`cat /export/scripts/$1 | awk ‘{print$1}‘`)
ip=(`cat /export/scripts/$1 | awk ‘{print$2}‘`)
port=(`cat /export/scripts/$1 | awk ‘{print$3}‘`)
user=$3
pass=$4
db_name=$5
time=`date +%Y%m%d`
touch /export/scripts/$time.txt
len=${#ip[*]}
num=0
while [ $num -lt $len ]
do
echo "=========== ${name[$num]} ============="
echo "=========== ${name[$num]} =============" >> /export/scripts/$time.txt
mysql -u$user -p$pass -h${ip[$num]} -P${port[$num]} $db_name < $2
let num++
done
本文出自 “云淡风轻” 博客,谢绝转载!
标签:example 服务器 master linux export
原文地址:http://liuminkun.blog.51cto.com/10171900/1684681