################################################################## # # # SHANGHAI BAOSIGHT CO. # # # # This script is create by Wei Shengyu # # # # 2011.10.21 # # # ################################################################## #!/bin/bash USER=$(awk -v key="db" -v RS='\\[[^\n]*]' 'v=="["key"]";{v=RT}' $CRGS/config/crgs.cfg|grep "user"|sed "s/user=//") PASSWORD=$(awk -v key="db" -v RS='\\[[^\n]*]' 'v=="["key"]";{v=RT}' $CRGS/config/crgs.cfg|grep "password"|sed "s/password=//") DBNAME=$(awk -v key="db" -v RS='\\[[^\n]*]' 'v=="["key"]";{v=RT}' $CRGS/config/crgs.cfg|grep "database"|sed "s/database=//") DBTYPE=$(awk -v key="db" -v RS='\\[[^\n]*]' 'v=="["key"]";{v=RT}' $CRGS/config/crgs.cfg|grep "dbtype"|sed "s/dbtype=//") if [ $# -lt 1 ]; then echo "At least one file" echo "useage:exesql [FILENAME]" fi declare -i s #if [ -n "$ORACLE_HOME" ]; then if [ "$DBTYPE" = "ORACLE" ]; then for (( i=1; i<=$#; i=i+1)) do dos2unix ${!i} sed -i -e '1s/^\xef\xbb\xbf//' ${!i} #remove bomb echo "@@${!i}" >>temp.sql done echo "exit" >>temp.sql sqlplus $USER/$PASSWORD@$DBNAME @temp.sql rm -f temp.sql #elif [ -n "$DB2HOME" ]; then elif [ "$DBTYPE" = "DB2" ]; then CODEPAGE=`db2set|grep DB2CODEPAGE` # get current db2 codepage db2set db2codepage=1208 db2 connect to $DBNAME user $USER using $PASSWORD for (( i=1; i<=$#; i=i+1)) do dos2unix ${!i} sed -i -e '1s/^\xef\xbb\xbf//' ${!i} #remove bomb db2 -td'@' -cf ${!i} done db2 connect reset db2set $CODEPAGE else echo Unknown DBTYPE in config/crgs.cfg! fi