文件名: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 ` #进程类型判断,如果为E开头则归类为抽取进程,如果P开头归类为发送进程 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 #判断,如果为EXTRACT进程则写入附加日志,如果为发送进程,则跳过 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
分享标题:OGG运维优化脚本(三)-信息修改类--快速加表
URL网址:https://www.cdcxhl.com/article18/ppdgdp.html
成都网站建设公司_创新互联,为您提供网站内链、做网站、商城网站、云服务器、微信公众号、域名注册
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联