#!/bin/bash
MYSQL_HOST="192.168.161.89"
MYSQL_USER="root"
MYSQL_PASSWD="123456"
#根据IP和主备类型,获取需要kill的redis实例的监听端口
sql="select s.port from dca_hosts h, dca_sources_extend s where h.ip='192.168.161.89' and h.host_id=s.host_id and s.is_master='1'"
port_list1=$(/opt/mysql-5.6.21/bin/mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWD dca -e "$sql");
for port in $port_list1
do
echo echo "PORT:"$port
done
echo
port_list2=$(/opt/mysql-5.6.21/bin/mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWD dca -e "$sql"|awk 'NR>1');
for port in $port_list2
do
echo echo "PORT:"$port
done
echo
/opt/mysql-5.6.21/bin/mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWD dca -e "$sql"|awk 'NR>1' | while read port
do
echo "PORT:"$port
done