您好,登錄后才能下訂單哦!
現在開始介紹腳本,所有的腳本必須在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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。