不一样的思想~~ http://shop34712791.taobao.com MSN:wins0910@hotmail.com

批量修改配置文件

上一篇 / 下一篇  2007-10-19 12:12:13 / 个人分类:待分析

#file:db_config_v1.2.sh
#author:sujh
#create time:2007-08-17 11:56
#describe:N/A
#check the option
while getopts ":hp:" opt;
do
   case $opt in
       h)
           printf "USAGE:\n sh $0 -p WORKPATH\n"
           exit 0
           ;;
       p)
           workPath=$OPTARG
           printf "Get the work-path:"${workPath}"\n"
           ;;
       :)
           printf ">> Error: '-$OPTARG' requires an argument \n please use: sh $0 -h \n"
           exit 1
           ;;
       ?)
           printf ">> Error: '-$OPTARG' not supported \n please use: sh $0 -h\n"
           exit 1
           ;;
   esac
done
#printf $OPTIND

if [ "$OPTIND" = "1" ];then
   printf "Error:Option '-p WORKPATH' is need\n"
   exit 1
fi

#shield interregnum
stty susp ^@#$
stty intr ^@$#
stty quit ^*#$

matchStr="<value>jdbc:oracle:thin:@.*<\/value>";

dbconf="<value>jdbc:oracle:thin:@10.17.42.111:1521:bnet</value>";

if cd ${workPath}; then
   localPath=`pwd`
   printf "Success to open WORKPATH:"$localPath"\n" 
   bakDir="BAKDIR"`date +%s`
   mkdir ${localPath}"/"${bakDir}
   printf "Created backup directory:"${bakDir}"\n"
   cp ./* ${bakDir}
   printf "Backup file complete\n"
   find $localPath -maxdepth 1 -type f -exec basename {} \;|xargs -i awk '{
       if(match($0,/'$matchStr'/))
           gsub(/'$matchStr'/,"'$dbconf'",$0);
       print "echo \""$0"\" >> {}.new"
   }' {} |sh
   printf "Update filename\n"
   find $localPath -maxdepth 1 -type f -

name "*.new"|awk '{print "mv "$0" " substr($0,0,length($0)-4)}'|sh
   printf "REPLACE COMPLETE\n"
else
   printf "Open WORKPATH(${wordPath}) fail\n"
fi
#resume interregnum
stty susp ^Z
stty intr ^C
stty quit ^\\
 


TAG: 待分析

 

评分:0

我来说两句

Open Toolbar