#!/bin/bash # 读取配置项 host=`sed '/^host =/!d;s/.*=//' /usr/local/mysql2pg/bin/my.cfg` port=`sed '/^port =/!d;s/.*=//' /usr/local/mysql2pg/bin/my.cfg` user=`sed '/^user =/!d;s/.*=//' /usr/local/mysql2pg/bin/my.cfg` password=`sed '/^password =/!d;s/.*=//' /usr/local/mysql2pg/bin/my.cfg` # 去掉双引号 host=`echo $host | sed -r 's/.*"(.+)".*/\1/'` port=`echo $port | sed -r 's/.*"(.+)".*/\1/'` user=`echo $user | sed -r 's/.*"(.+)".*/\1/'` password=`echo $password | sed -r 's/.*"(.+)".*/\1/'` #获取BINLOG文件名称和偏移量 binlogfile=`mysql -h$host -u$user -p$password -P$port -e "show master status;" | awk '{if (NR>1){print $1}}'` binlogfile_offset=`mysql -h$host -u$user -p$password -P$port -e "show master status;" | awk '{if (NR>1){print $2}}'` mysql -h$host -u$user -p$password -P$port -e "show master status;" #echo $binlogfile #echo $binlogfile_offset sed -i "s/^binlogfile =.*/binlogfile = \"$binlogfile\"/" /usr/local/mysql2pg/bin/my.cfg sed -i "s/^binlogfile_offset =.*/binlogfile_offset = \"$binlogfile_offset\"/" /usr/local/mysql2pg/bin/my.cfg #cat /usr/local/mysql2pg/bin/my.cfg echo '恭喜,已成功更新配置文件的binlog日志名称和偏移量!'