-
#!/bin/bash
-
-
filepath=$(cd "$(dirname "$0")"; pwd)
-
name=$HOSTNAME
-
mysqluser=mysql
-
server_ip=192.168.207.212
-
mysqlip=10.27.81.100
-
echo "insert into MONITOR3.BASE_INFO(IP,HOST_NAME,INS_NAME)values ($mysqlip,'$name','$mysqluser');">$filepath/insert.sql
-
echo "select ip from MONITOR3.BASE_INFO where ip='$mysqlip';">>$filepath/insert.sql
-
su - $mysqluser -c "scp -r $filepath/insert.sql db2inst1@$server_ip:/home/db2inst1" 2>&1 >2.log
-
check_insert=`su - $mysqluser -c "ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=20 -o StrictHostKeyChecking=no -o ConnectionAttempts=5 -o PasswordAuthentication=no -o BatchMode=yes -p 22 db2inst1@$server_ip 'db2 connect to mondb;db2 -tf /home/db2inst1/insert.sql'"` 2>&1 >2.log
-
check_insert=`echo "$check_insert" |grep $mysqlip`
-
-
if [[ "${check_insert}" == "" ]
-
then
-
echo "`date` - [error] '$mysqlip' insert into db2 server($server_ip) error ,Please check the script!Error code:701" 2>&1 >2.log
-
exit 701
-
else
-
echo "`date` - [info] '$mysqlip' insert into db2 server($server_ip) successfully!" 2>&1 >2.log
-
fi
autossh 需要提前配置好。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29071259/viewspace-1379761/
,如需转载,请注明出处,否则将追究法律责任。