OGG运维优化脚本(二. 五)-信息修改类--快速加表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OGG运维优化脚本(二. 五)-信息修改类--快速加表相关的知识,希望对你有一定的参考价值。
文件名:add.sh
所在路径:$HOME/ggadd
功能:批量加表脚本的优化版,用于针对少量加表需求,包括重复配置表过滤功能以及附加日志自动增加功能
该脚本通过alias方式写入账户系统配置文件.profile 和.bash_profile通过命令使用
日志路径:$HOME/ggscript/ggadd
具体脚本内容
#!/bin/bash if [ $# -eq 0 ]; then echo "info EXTRACT TABLE AREA user" exit 2 fi if [ $# -eq 1 ]; then echo "info EXTRACT TABLE AREA user" exit 2 fi if [ $# -eq 2 ]; then echo "info EXTRACT TABLE AREA user" exit 2 fi if [ $# -eq 3 ]; then echo "info EXTRACT TABLE AREA user" exit 2 fi backuptime=`date +%Y%m%d-%H%M` datenow=`date +%Y%m%d%H` echo $backuptime > ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ cd $HOME/ggscript/ggadd echo $backuptime echo "This script can only insert one table( by RenYi)" val=$1 echo $2 > AddTemp area=$3 name=$4 #echo $val cat AddTemp #echo $area echo "--------insert process name------" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo $val >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ val=`echo $val|tr a-z A-Z ` if [ `echo $val|grep ^E` ];then IType=EXTRACT elif [ `echo $val|grep ^P` ];then IType=POST elif [ `echo $val|grep ^R` ];then echo "can not operate the REPLICAT process" echo "can not operate the REPLICAT process" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo "process break off" echo "process break off" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ exit 2 else echo "only can operate the EXTRACT and the POST process" echo "can not operate the REPLICAT process" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo "process break off" echo "process break off" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ exit 2 fi val=`echo $val.PRM|tr A-Z a-z` echo $val echo "--------insert file name------" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo $val >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ cd $HOME/ggserver/dirprm if [ ! -e $val ]; then echo "the EXTRACT is not exist" echo "the EXTRACT is not exist" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ exit 2 fi cd $HOME/ggscript/ggadd echo $val cat $HOME/ggserver/dirprm/$val |grep Begin|sed ‘s/--//g‘|sed ‘s/-Begin//g‘ > arealist cat arealist echo "------------area check-------------- " >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ check=`grep -w $area arealist` if [ "$check" = "$area" ];then echo "area is exist" echo "area is exist" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ else echo "area is not exist" #echo "area is not exist" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ #exit 2 fi 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 AddedTemp2 |sort -n > AddTable comm -12 AddTable AddTemp > Duplicate echo "--------Table Check---------------" cat AddTemp >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo "--------Table Check---------------">> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ check=`grep -w $2 Duplicate` if [ "$check" = "$2" ];then echo "The table has being added" echo "The table has being added" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ echo "process break off" exit 2 else echo "The table not be add" echo "The table not be add" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ fi cp $HOME/ggserver/dirprm/$val $HOME/ggserver/dirprm/bak/$val.$backuptime.bak echo "backup complete" echo "backup complete" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ sed ‘s/^/TABLE /‘ AddTemp > table1 sed ‘s/$/;/‘ table1 > table2 rm -f table1 echo "-----The Operator is ‘$name‘--------" >> ‘‘$HOME‘/gglog/ggadd/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 if [ "$IType" == "EXTRACT" ];then sed ‘s/^/add trandata /‘ AddTemp > addtrandata cd $HOME/ggserver echo dblogin `more $HOME/ggserver/dirprm/$val|grep USERID` > dirdat/addtrandata cat $HOME/ggscript/ggadd/addtrandata >> dirdat/addtrandata echo OBEY dirdat/addtrandata |./ggsci echo "process complete" echo "process complete" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ exit 2 elif [ "$IType" == "POST" ];then echo "process complete" echo "process complete" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ exit 2 else echo "process complete" echo "process complete" >> ‘‘$HOME‘/gglog/ggadd/InsertLog-‘$backuptime‘.log‘ fi
本文出自 “netsman” 博客,请务必保留此出处http://netsman.blog.51cto.com/5750076/1939628
以上是关于OGG运维优化脚本(二. 五)-信息修改类--快速加表的主要内容,如果未能解决你的问题,请参考以下文章