mysql数据传递到前端_linux环境下shell编程控制mysql后端表数据传递到前端

项目的目标:

1)配合开发,将前端应用程序与后端应用程序分离

2)后端置于NAT后,允许内部的***访问(open***与本项目无关,不详写)

3)前端支持同时发布与N个服务器

项目模块:

整套脚本分为以下几个模块:

1)源表与目标表差异检查模块-diffTab.sh

2)源表导出模块-exportData.sh

3)目标表导入模块-importData.sh

4)数据转表模块-swpToTable.sh

5)底层应用程序或图片同步模块-rsyncImg.sh

6)主控模块-man.sh

尚未开发的模块:

1)存储过程自动生成模块-addProcedure.sh(老大不让写,这是我个人想法)

2)主控模块参数自动配置模块(从mysql数据库的表读取参数送到主模块运行)

diffTab.sh模块代码:#!/bin/bash

souHost=$1

souPort=$2

souUser=$3

souPwd=$4

souDBName=$5

souDBTab=$6

desHost=$7

desPort=$8

desUser=$9

desPwd=${10}

desDBName=${11}

desDBTab=${12}

sDif=$souHost.$souDBName.$souDBTab.dif

dDif=$desHost.$desDBName.$souDBTab.dif

log=/var/log/$0.log

if [ $# != 12 ]; then

echo "$0           "

echo "  Please enter ip address or domain name,127.0.0.1 192.168.x.x www.example.com"

echo "example:$0 '192.168.1.241' '3306' 'root' 'abc@123' 'mysql' 'user1' 'host1' '192.168.1.206' '3306' 'root' 'abc@321' 'mysql' 'user2' 'host2'"

exit 1

elif [ ! -n "$souHost" ]; then

echo "Source ip address cannot be empty!"

exit 1

elif [ ! -n "$souPort" ]; then

echo "Source database Port cannot be empty!"

exit 1

elif [ ! -n "$souUser" ]; then

echo "Source database user name cannot be empty!"

exit 1

elif [ ! -n "$souPwd" ]; then

echo "Source database password cannot be empty!"

exit 1

elif [ ! -n "$souDBName" ]; then

echo "Source database name cannot be empty!"

exit 1

elif [ ! -n "$souDBTab" ]; then

echo "Source database table name cannot be empty!"

exit 1

elif [ ! -n "$desHost" ]; then

echo "Destination ip address cannot be empty!"

exit 1

elif [ ! -n "$desPort" ]; then

echo "DataBase Port cannot be empty!"

exit 1

elif [ ! -n "$desUser" ]; then

echo "Destination database user name cannot be empty!"

exit 1

elif [ ! -n "$desPwd" ]; then

echo "Destination database password cannot be empty!"

exit 1

elif [ ! -n "$desDBName" ]; then

echo "Destination database name cannot be empty!"

exit 1

elif [ ! -n "$desDBTab" ]; then

echo "Destination database table name cannot be empty!"

exit 1

fi

(echo >/dev/tcp/$souHost/$souPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unable connect to Host:$souHost:$souPort" >> $log

exit 1

fi

(echo >/dev/tcp/$desHost/$desPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unable connect to host:$desHost:$desPort" >> $log

exit 1

fi

mysql -h$souHost -u$souUser -p$souPwd -e "exit" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Source host:$desHost user name or password error" >> $log

exit 1

fi

mysql -h$desHost -u$desUser -p$desPwd -e "exit" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Destination host:$souHost user name or password error" >> $log

exit 1

fi

mysql -h$souHost -u$souUser -p$souPwd -e "use $souDBName" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Source host:$souHost unknown database [$souDBName]" >> $log

exit 1

fi

mysql -h$desHost -u$desUser -p$desPwd -e "use $desDBName" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Destination host:$desHost unknown database [$desDBName]" >> $log

exit 1

fi

mysql -h$souHost -u$souUser -p$souPwd -e "desc $souDBName.$souDBTab" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Destination host:$souHost Table [$souDBTab] doesn't exist" >> $log

exit 1

else

mysql -h$souHost -u$souUser -p$souPwd -e "desc $souDBName.$souDBTab" >$sDif

fi

mysql -h$desHost -u$desUser -p$desPwd -e "desc $desDBName.$desDBTab" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Destination host:$desHost Table [$desDBTab] doesn't exist" >> $log

exit 1

else

mysql -h$desHost -u$desUser -p$desPwd -e "desc $desDBName.$desDBTab" > $dDif

fi

if [ -f $sDif ] && [ -f $dDif ]; then

wcR=$(diff $sDif $dDif | grep '^>' | wc -l)

wcL=$(diff $sDif $dDif | grep '^

let wcS=$wcR+$wcL

if [ $wcS != 0 ]; then

echo "`date` $0 error:$souHost.$souDBName.$souDBTab and $desHost.$desDBName.$souDBTab are inconsistent!" >> $log

diff $sDif $dDif >> $log

fi

echo $wcS

fi

if [ -f $sDif ]; then

rm -rf $sDif

fi

if [ -f $dDif ]; then

rm -rf $dDif

fi

exportData.sh模块代码:#!/bin/bash

souHost=$1

dbPort=$2

dbUser=$3

dbPwd=$4

dbName=$5

dbTab=$6

dbFlag=$7

desHost=$8

desDBName=$9

mark=m

dbStatus=log_status

dbLotNO=lot_NO

swpTab=$dbTab"_swp"

dt=$(date +"%Y%m%d%H%M%S")

extSql=$(echo $souHost | tr -d ".")"."$dbName.$dbTab"."$(echo $desHost | tr -d ".")"."$dt".sql"

log=/var/log/$0.log

if [ ! $# -ge 8 ]; then

echo "$0         [desDBName]"

echo "  Please enter ip address or domain name,127.0.0.1 192.168.x.x www.example.com"

echo " Please enter conlumn name, values is i / d / u"

echo "example:$0 '127.0.0.1' '3306' 'root' 'abc@123' 'mysql' 'user' 'host' 192.168.1.*"

exit 1

elif [ ! -n "$souHost" ]; then

echo "Source ip address cannot be empty!"

exit 1

elif [ ! -n "$dbPort" ]; then

echo "Source database Port cannot be empty!"

exit 1

elif [ ! -n "$dbUser" ]; then

echo "Source database username cannot be empty!"

exit 1

elif [ ! -n "$dbPwd" ]; then

echo "Source database password cannot be empty!"

exit 1

elif [ ! -n "$dbName" ]; then

echo "Source database name cannot be empty!"

exit 1

elif [ ! -n "$dbTab" ]; then

echo "Source database table name cannot be empty!"

exit 1

elif [ ! -n "$dbStatus" ]; then

echo "Source database column cannot be empty!"

exit 1

elif [ ! -n "$desHost" ]; then

echo "Detination ip address cannot be empty!"

exit 1

elif [ "$desDBName" != "" ]; then

extSql=$(echo $souHost | tr -d ".")"."$desDBName.$dbTab"."$(echo $desHost | tr -d ".")"."$dt".sql"

fi

(echo >/dev/tcp/$souHost/$dbPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unable connect to Host:$souHost:$dbPort" >> $log

exit 1

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "exit" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 User name or password error" >> $log

exit 1

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "use $dbName" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unknown database [$dbName]" >> $log

exit 1

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "desc $dbName.$swpTab" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "create table $dbName.$swpTab (select * from $dbName.$dbTab where 1=2)"

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "select $dbFlag from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbFlag varchar(255)"

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "select $dbStatus from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbStatus varchar(255)"

fi

mysql -h$souHost -u$dbUser -p$dbPwd -e "select $dbLotNO from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbLotNO varchar(255)"

fi

count=0

rt=$(mysql -h$souHost -u$dbUser -p$dbPwd -e "select count(*) from $dbName.$swpTab" 2> /dev/null)

if [ $? = 0 ]; then

count=$(echo $rt | cut -d" " -f2)

else

echo "`date` $0 error:select count(*) from $dbName.$swpTab" >> $log

exit 1

fi

if [ $count = 0 ]; then

echo "count = $count"

exit 0

fi

if [ $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "update $dbName.$swpTab set $dbStatus = 'm',$dbLotNO = $dt"

else

echo "`date` $0 error:alter table $dbName.$swpTab add $dbStatus" >> $log

exit 1

fi

if [ $? = 0 ]; then

mysqldump -h$souHost -u$dbUser -p$dbPwd -w "$dbStatus = 'm'" -t $dbName $swpTab > $extSql

else

echo "`date` $0 error:update $dbName.$swpTab set $dbStatus = 'm'" >> $log

exit 1

fi

if [ $? = 0 ]; then

mysql -h$souHost -u$dbUser -p$dbPwd -e "delete from $dbName.$swpTab where $dbStatus = 'm'"

else

rm -rf $extSql

echo "`date` $0 error:mysqldump -h$souHost -u$dbUser -p$dbPwd -w $dbStatus = 'm'" >> $log

exit 1

fi

if [ $? = 0 ]; then

exit 0

else

echo "`date` $0 error:delete from $dbName.$swpTab where $dbStatus = 'm'" >> $log

exit 1

fi

importData.sh模块代码:#!/bin/bash

desHost=$1

dbPort=$2

dbUser=$3

dbPwd=$4

dbName=$5

dbTab=$6

dbFlag=$7

souHost=$8

mark=m

dbStatus=log_status

dbLotNO=lot_NO

swpTab=$dbTab"_swp"

dt=$(date +"%Y%m%d%H%M%S")

extSql=$(echo $souHost | tr -d ".")"."$dbName.$dbTab"."$(echo $desHost | tr -d ".")".*.sql"

log=/var/log/$0.log

if [ $# != 8 ]; then

echo "$0        "

echo "  Please enter ip address or domain name,127.0.0.1 192.168.x.x www.example.com"

echo " Please enter conlumn name, values is i / d / u"

echo "example:$0 '192.168.1.*' '3306' 'root' 'abc@123' 'mysql' 'user' 'host' '127.0.0.1'"

exit 1

elif [ ! -n "$desHost" ]; then

echo "Detination ip address cannot be empty!"

exit 1

elif [ ! -n "$dbPort" ]; then

echo "DataBase Port cannot be empty!"

exit 1

elif [ ! -n "$dbUser" ]; then

echo "DataBaseUserName cannot be empty!"

exit 1

elif [ ! -n "$dbPwd" ]; then

echo "DataBasePassword cannot be empty!"

exit 1

elif [ ! -n "$dbName" ]; then

echo "DataBaseName cannot be empty!"

exit 1

elif [ ! -n "$dbTab" ]; then

echo "DataBaseTableName cannot be empty!"

exit 1

elif [ ! -n "$dbStatus" ]; then

echo "DataBaseColumn cannot be empty!"

exit 1

elif [ ! -n "$souHost" ]; then

echo "Source ip address cannot be empty!"

exit 1

fi

(echo >/dev/tcp/$desHost/$dbPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unable connect to Host:$desHost:$dbPort" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "exit" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 User name or password error" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "use $dbName" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unknown database [$dbName]" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "desc $dbName.$dbTab" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$dbTab] doesn't exist" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "desc $dbName.$swpTab" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$desHost -u$dbUser -p$dbPwd -e "create table $dbName.$swpTab (select * from $dbName.$dbTab where 1=2)"

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbFlag from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$desHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbFlag varchar(255)"

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbStatus from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$desHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbStatus varchar(255)"

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbLotNO from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

mysql -h$desHost -u$dbUser -p$dbPwd -e "alter table $dbName.$swpTab add $dbLotNO varchar(255)"

fi

ls $extSql &> /dev/null

if [ ! $? = 0 ]; then

echo "No such $extSql file!"

exit 0

fi

for i in $(ls $extSql | sort)

do

mysql -h$desHost -u$dbUser -p$dbPwd $dbName 

if [ $? = 0 ]; then

mv -f $i $(echo $i | awk  -F '.'  '{print $1"."$2"."$3"."$4"."$5".swp"}')

else

echo "`date` $0 error:import [$i] error" >> $log

fi

done

if [ $? = 0 ]; then

exit 0

else

echo "`date` $0 error:import tables error" >> $log

exit 1

fi

swpToTable.sh模块代码:#!/bin/bash

desHost=$1

dbPort=$2

dbUser=$3

dbPwd=$4

dbName=$5

dbTab=$6

dbFlag=$7

souHost=$8

mark=m

dbStatus=log_status

dbLotNO=lot_NO

swpTab=$dbTab"_swp"

dt=$(date +"%Y%m%d%H%M%S")

extSql=$(echo $souHost | tr -d ".")"."$dbName.$dbTab"."$(echo $desHost | tr -d ".")".*.swp"

log=/var/log/$0.log

if [ $# != 8 ]; then

echo "$0        "

echo "  Please enter ip address or domain name,127.0.0.1 192.168.x.x www.example.com"

echo " Please enter conlumn name, values is i / d / u"

echo "example:$0 '192.168.1.*' '3306' 'root' 'abc@123' 'mysql' 'user' 'host' '127.0.0.1'"

exit 1

elif [ ! -n "$desHost" ]; then

echo "Detination ip address cannot be empty!"

exit 1

elif [ ! -n "$dbPort" ]; then

echo "DataBase Port cannot be empty!"

exit 1

elif [ ! -n "$dbUser" ]; then

echo "DataBaseUserName cannot be empty!"

exit 1

elif [ ! -n "$dbPwd" ]; then

echo "DataBasePassword cannot be empty!"

exit 1

elif [ ! -n "$dbName" ]; then

echo "DataBaseName cannot be empty!"

exit 1

elif [ ! -n "$dbTab" ]; then

echo "DataBaseTableName cannot be empty!"

exit 1

elif [ ! -n "$dbStatus" ]; then

echo "DataBaseColumn cannot be empty!"

exit 1

elif [ ! -n "$souHost" ]; then

echo "Source ip address cannot be empty!"

exit 1

fi

(echo >/dev/tcp/$desHost/$dbPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unable connect to Host:$desHost:$dbPort" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "exit" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 User name or password error" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "use $dbName" &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 Unknown database [$dbName]" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "desc $dbName.$dbTab" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$dbTab] doesn't exist" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "desc $dbName.$swpTab" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$swpTab] doesn't exist" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbFlag from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$swpTab] conlumn [$dbFlag] doesn't exist" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbStatus from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$swpTab] conlumn [$dbStatus] doesn't exist" >> $log

exit 1

fi

mysql -h$desHost -u$dbUser -p$dbPwd -e "select $dbLotNO from $dbName.$swpTab where 1=2" &> /dev/null

if [ ! $? = 0 ]; then

echo  "`date` $0 Table [$swpTab] conlumn [$dbLotNO] doesn't exist" >> $log

exit 1

fi

ls $extSql &> /dev/null

if [ ! $? = 0 ]; then

echo "No such $extSql file!"

exit 0

fi

count=0

rt=0

for i in $(ls $extSql | sort)

do

fLotNO=$(echo $i | awk  -F '.'  '{print $5}')

rn=$(echo $i | awk  -F '.'  '{print $1"."$2"."$3"."$4"."$5".log"}')

rt=$(mysql -h$desHost -u$dbUser -p$dbPwd -e "select count(*) from $dbName.$swpTab where $dbLotNO = $fLotNO and

($dbFlag = 'i' or $dbFlag = 'd' or $dbFlag = 'u')") 2> /dev/null

count=0

count=$(echo $rt | cut -d" " -f2)

if [ $count != 0 ]; then

mysql -h$desHost -u$dbUser -p$dbPwd -e "call $dbName.to_$dbTab($(echo $i | awk  -F '.'  '{print $5}'))" &> /dev/null

fi

count=1

rt=$(mysql -h$desHost -u$dbUser -p$dbPwd -e "select count(*) from $dbName.$swpTab where $dbLotNO = $fLotNO and

($dbFlag = 'i' or $dbFlag = 'd' or $dbFlag = 'u')") 2> /dev/null

count=$(echo $rt | cut -d" " -f2)

if [ ! -d log ]; then

mkdir log

fi

if [ $count = 0 ]; then

mv $i log/$rn

fi

done

if [ $? = 0 ]; then

exit 0

else

echo "`date` $0 error:swp to tables error" >> $log

exit 1

fi

rsyncImg.sh模块代码:#!/bin/bash

souHost=$1

souPort=$2

souUser=$3

souPwd=$4

souRoot=$5

souDir=$6

desHost=$7

desPort=$8

desUser=$9

desPwd=${10}

desRoot=${11}

desDir=${12}

sf=/tmp/auto_rsync.sh

log=/var/log/$0.log

if [ $# != 12 ]; then

echo "$0            "

echo "  Please enter ip address or domain name,127.0.0.1 192.168.x.x www.example.com"

echo "example:$0 '192.168.1.241' '22' 'root' 'abc@123' '/var/ftp/' 'img/' '192.168.1.206' '22' 'root' 'abc@321' '/var/ftp/' 'img/'"

exit 1

elif [ ! -n "$souHost" ]; then

echo "Source ip address cannot be empty!"

exit 1

elif [ ! -n "$souPort" ]; then

echo "Source database Port cannot be empty!"

exit 1

elif [ ! -n "$souUser" ]; then

echo "Source database user name cannot be empty!"

exit 1

elif [ ! -n "$souPwd" ]; then

echo "Source database password cannot be empty!"

exit 1

elif [ ! -n "$souRoot" ]; then

echo "Source dir root cannot be empty!"

exit 1

elif [ ! -n "$souDir" ]; then

echo "Source  dir cannot be empty!"

exit 1

elif [ ! -n "$desHost" ]; then

echo "Destination ip address cannot be empty!"

exit 1

elif [ ! -n "$desPort" ]; then

echo "DataBase Port cannot be empty!"

exit 1

elif [ ! -n "$desUser" ]; then

echo "Destination database user name cannot be empty!"

exit 1

elif [ ! -n "$desPwd" ]; then

echo "Destination database password cannot be empty!"

exit 1

elif [ ! -n "$desRoot" ]; then

echo "Destination dir root cannot be empty!"

exit 1

elif [ ! -n "$desDir" ]; then

echo "Destination dir name cannot be empty!"

exit 1

fi

if [ $souHost$souRoot$souDir = $desHost$desRoot$desDir ]; then

echo "`date` $0 error:Source address and destination address cannot be the same!" >> $log

exit 1

fi

(echo >/dev/tcp/$souHost/$souPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 error:Unable connect to Host:$souHost:$souPort" >> $log

exit 1

fi

(echo >/dev/tcp/$desHost/$desPort) &> /dev/null

if [ ! $? = 0 ]; then

echo "`date` $0 error:Unable connect to host:$desHost:$desPort" >> $log

exit 1

fi

if [ ! -f /usr/bin/expect ]; then

yum -y install expect.x86_64

fi

if [ ! -f /usr/bin/expect ]; then

echo "`date` $0 error:Unable installl expect.x86_64" >> $log

exit 1

fi

auto_scp () {

expect -c "set timeout -1;

spawn scp -r -P $2 $3 $4;

expect {

*assword:* {send -- $1\r;

expect {

*denied* {exit 2;}

eof

}

}

eof         {exit 1;}

}

"

return $?

}

auto_ssh () {

expect -c "set timeout -1;

spawn ssh -p $2 -o StrictHostKeyChecking=no $3 ${@:4};

expect {

*assword:* {send -- $1\r;

expect {

*denied* {exit 2;}

eof

}

}

eof         {exit 1;}

}

"

return $?

}

(cat <

if [ ! -f /usr/bin/expect ]; then

yum -y install expect.x86_64

fi

auto_rsync () {

expect -c "set timeout -1;

spawn rsync -av --delete --port \$2 \$3 \$4;

expect {

*assword:* {send -- \$1\r;

expect {

*denied* {exit 2;}

eof

}

}

eof         {exit 1;}

}

"

return \$?

}

if [ -d $souRoot$souDir ]; then

auto_rsync '$desPwd' $desPort $souRoot$souDir $desUser@$desHost:$desRoot$souDir

fi

exit

eof

) > $sf

if [ -f $sf ]; then

auto_scp $souPwd $souPort $sf $souUser@$souHost:$sf

fi

rt=0

if [ $? = 0 ]; then

auto_ssh $souPwd $souPort $souUser@$souHost "bash $sf && rm $sf"

rt=$?

fi

if [ -f $sf ]; then

rm -rf $sf

fi

echo $rt

man.sh主控模块:#!/bin/bash

cd /root/script

./rsyncImg.sh '127.0.0.1' '22' 'user' 'abc123' '/var/ftp/' 'img/' '43.255.0.1' '22' 'user' 'abc123' '/var/ftp/' 'img/'

./rsyncImg.sh '127.0.0.1' '22' 'user' 'abc123' '/home/' 'mysqluser_ihouse/' '43.255.0.1' '22' 'user' 'abc123' '/home/' 'mysqluser_ihouse/'

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_mysqluser_houserent' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_houserent')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_mysqluser_houserent' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_houserent' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_houserent' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_mysqluser_housesell' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_housesell')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_mysqluser_housesell' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_housesell' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_mysqluser_housesell' 'log_flag' '127.0.0.1'

fi

#

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_house_wanted' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_house_wanted')

if [ $rt = 0 ]; then

./exportData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_house_wanted' 'log_flag' '127.0.0.1' 'zj_ihouse'

./importData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_house_wanted' 'log_flag' '43.255.0.1'

./swpToTable.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_house_wanted' 'log_flag' '43.255.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_broker_info' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_broker_info')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_broker_info' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_broker_info' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_broker_info' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'sys_area' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'sys_area')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'sys_area' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'sys_area' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'sys_area' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_advert' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_advert')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_advert' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_advert' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_advert' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_about' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_about')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_about' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_about' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_about' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_borough' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_borough')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_borough' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_borough' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_borough' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_houserent_pic' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_houserent_pic')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_houserent_pic' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_houserent_pic' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_houserent_pic' 'log_flag' '127.0.0.1'

fi

rt=1

rt=$(./diffTab.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_housesell_pic' '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_housesell_pic')

if [ $rt = 0 ]; then

./exportData.sh '127.0.0.1' '3306' 'mysqluser' abc123' 'zj_ihouse' 'zj_housesell_pic' 'log_flag' '43.255.0.1' 'zj_mysqluser_ihouse'

./importData.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_housesell_pic' 'log_flag' '127.0.0.1'

./swpToTable.sh '43.255.0.1' '3306' 'mysqluser' abc123' 'zj_mysqluser_ihouse' 'zj_housesell_pic' 'log_flag' '127.0.0.1'

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值