现在开始介绍脚本,所有的脚本必须在prm配置文件添加注释后才能成功使用
详细请参考 脚本部署准备
实际的运维过程中,我们的OGG程序都统一部署在$home/ggserver路径下,
批量加表
文件名: insert.sh
脚本所在路径:$HOME/ggscript/gginsert
功能:为满足应用时常提出的大批量增加同步表需求
用于批量加表,包括重复配置表过滤功能以及附加日志自动增加功能
该脚本通过edit脚本选择调用
该脚本目前只能对EXTRACT和发送进程生效
日志路径: $HOME/gglog/gginsert
#!/bin/bash backuptime=`date +%Y%m%d-%H%M` datenow=`date +%Y%m%d%H` cd $HOME/ggscript/gginsert echo $backuptime echo "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:" val echo "--------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 Begin read -p "Please enter the Area name:" area echo "--------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 1 vi AddTemp echo "-----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++}' > temp awk -F '--' '($1) { print $1}' temp > temp2 rm -rf temp sed -e '/^$/d' temp2 > temp3 rm -rf temp2 awk -F ',' '{print $1}' temp3 >temp4 rm -rf temp3 awk -F ';' '{print $1}' temp4 >temp5 rm -rf temp4 echo "Confirm the tables that have increased" cat temp5|awk -F 'TABLE ' '{print $2}' > AddedTemp rm -rf temp5 sed '/^$/d' AddedTemp > AddedTemp2 sed '/^$/d' AddTemp > AddTemp2 cat AddTemp2 |sort -n > AddTable cat AddedTemp2 |sort -n > AddedTable rm -f AddTemp comm -12 AddTable AddedTable > Duplicate num=`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 > NeedToAdd num=`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:" con if [ "$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 > table3 rm -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:" conb if [ "$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 2 fi
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。