千家信息网

OGG运维优化脚本(二)-信息修改类--批量加表

发表于:2024-12-01 作者:千家信息网编辑
千家信息网最后更新 2024年12月01日,现在开始介绍脚本,所有的脚本必须在prm配置文件添加注释后才能成功使用详细请参考 脚本部署准备实际的运维过程中,我们的OGG程序都统一部署在$home/ggserver路径下,批量加表文件名: ins
千家信息网最后更新 2024年12月01日OGG运维优化脚本(二)-信息修改类--批量加表

现在开始介绍脚本,所有的脚本必须在prm配置文件添加注释后才能成功使用

详细请参考 脚本部署准备

实际的运维过程中,我们的OGG程序都统一部署在$home/ggserver路径下,


批量加表

文件名: insert.sh

脚本所在路径:$HOME/ggscript/gginsert

功能:为满足应用时常提出的大批量增加同步表需求

用于批量加表,包括重复配置表过滤功能以及附加日志自动增加功能

该脚本通过edit脚本选择调用

该脚本目前只能对EXTRACT发送进程生效

日志路径: $HOME/gglog/gginsert


#!/bin/bashbackuptime=`date +%Y%m%d-%H%M`datenow=`date +%Y%m%d%H` cd $HOME/ggscript/gginsertecho $backuptimeecho "This script will search for the table that has been added and insert new table( by RenYi)"echo $backuptime > ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'ls -lrt $HOME/ggserver/dirprm/e*.prm $HOME/ggserver/dirprm/p*.prm$val#输入需操作的进程对应文件名(prm结尾)read -p "Please enter the prm file name:"  valecho "--------insert file name------" >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'echo $val >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'#输入需要批量增加表对应的区域cat $HOME/ggserver/dirprm/$val|grep Beginread -p "Please enter the Area name:" areaecho "--------insert area------" >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'echo $area >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'#在vi界面内粘贴需要增加的表名(无TABLE前缀,无分号结尾,请勿插入空格)echo "Please Enter the table you want to add(Please enter any key)-Do not include spaces!"read -n 1vi AddTempecho "-----insert table------"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'cat  AddTemp >>  ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'#echo $val#echo "awk '/--$area-Begin/,/--$area-End/{if(i>1)print x;x=$1;i++}' $HOME/ggserver/dirprm/$val"#重复表比对过滤cat $HOME/ggserver/dirprm/$val|awk '/--'$area'-Begin/,/--'$area'-End/{if(i>1)print x;x=$0;i++}' > tempawk -F '--'  '($1) { print $1}' temp > temp2rm -rf tempsed  -e '/^$/d'  temp2 > temp3rm -rf temp2awk -F ',' '{print $1}' temp3 >temp4rm -rf temp3awk -F ';' '{print $1}' temp4 >temp5rm -rf temp4echo "Confirm the tables that have increased"cat temp5|awk  -F 'TABLE '  '{print $2}' > AddedTemprm -rf temp5sed '/^$/d' AddedTemp > AddedTemp2sed '/^$/d' AddTemp > AddTemp2cat AddTemp2 |sort -n > AddTablecat AddedTemp2 |sort -n > AddedTablerm -f AddTempcomm -12  AddTable AddedTable > Duplicatenum=`sed -n '$=' Duplicate`echo "Check out the already added table in file "Duplicate",there were  '$num'  tables has being added"echo "---------The already added table---------"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'cat Duplicate >>  ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'comm -23  AddTable AddedTable > NeedToAddnum=`sed -n '$=' NeedToAdd`echo "Check out the Not yet add table in file "NeedToAdd",,there are  '$num'  tables not add"echo "---------The not yet added table---------"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'cat NeedToAdd >>  ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'#rm -rf AddedTable#rm -rf AddTable#表插入操作echo "Do you want to insert the table into '$val'?"read -p "Please enter y or n:"  conif [ "$con" == "y" ]                then                        echo "backup the '$val' to the '$HOME/ggserver/dirprm/bak/$val.$backuptime.bak'"                        echo "backup the '$val' to the '$HOME/ggserver/dirprm/bak/$val.$backuptime.bak'"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                        cp $HOME/ggserver/dirprm/$val $HOME/ggserver/dirprm/bak/$val.$backuptime.bak                        echo "backup complete"                        echo "backup complete" >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                        echo "modifying table "                        sed 's/^/TABLE /' NeedToAdd > table1                        sed 's/$/;/' table1 > table2        num=`sed -n '$=' table2`                        rm -f table1                        read -p "Please enter your name:" name                        echo "-----The Operator is '$name'--------" >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                        echo "inserting '$num' tables into '$val' "                        echo "inserting '$num' tables into '$val' " >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                        sed  '1 i\--'$datenow'-'$name'-add                        ' table2 > table3rm -f table2                        mv table3 table2                echo "inserting table"                        sed  '/'$area'-Insert/r table2                        ' $HOME/ggserver/dirprm/$val > $HOME/ggserver/dirprm/tem3                rm -f $HOME/ggserver/dirprm/$val                mv $HOME/ggserver/dirprm/tem3 $HOME/ggserver/dirprm/$val                echo "insert complete"                echo "---------insert complete"--------- >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                else                        echo "process complete"                        echo "process complete"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'fi#附加日志增加操作echo "Do you want to addtrandata?"read -p "Please enter y or n:"  conbif [ "$conb" == "y" ]                then                sed 's/^/add trandata /' NeedToAdd > addtrandata                NUX=`sed -n '$=' addtrandata`#               echo $NUX                        i=1#echo $i                cd $HOME/ggserver                        echo dblogin `more $HOME/ggserver/dirprm/$val|grep USERID` > dirdat/addtrandata#echo $login                        while [ "$i" -le "$NUX" ]                                do                                 sed -n "${i}p"  $HOME/ggscript/gginsert/addtrandata >> dirdat/addtrandata                                i=`expr $i + 1`                        done                        echo   OBEY dirdat/addtrandata |./ggsci                else                echo "process complete"                echo "process complete"  >> ''$HOME'/ggscript/gginsert/log/InsertLog-'$backuptime'.log'                exit 2fi




0