Extract Oracle Data with OCIULDR
Main script :
#/bin/bash
if [ $# -lt 6 ]
then
echo "Please use arguments, $0 [USERNAME] [PASSWORD] [SID] [SQLFILE] [SCHEMA] [MAX THREAD]"
exit 1
fi
######INITIAL PARAMETER
#-[ You must configure this directory ] -----------------------------#
OUTDIR=/oth02/spoll/
TMPDIR=/oth02/spoll/tmp
USERNAME=$1
PASSWORD=$2
SID=$3
sList=$4
SCHEMA=$5
max_thread=$6
THREADID=0
##max_thread=5
######FUNCTION
function cSQL(){
tablename=$1
cat << EOF > ${TMPDIR}/${tablename}.sql
SELECT *
FROM $tablename
EOF
}
function start() {
for tablename in `cat $sList`
do
##identified any threads
sFlag=0
while [ $sFlag -eq 0 ]
do
NEXT_PROC=`ls ${SCHEMA}_*.lock | wc -l`
if [ $NEXT_PROC -le $max_thread ]
then
sFlag=1
else
sleep 15
fi
done
#running others threads
touch ${SCHEMA}_${THREADID}.lock
cSQL $tablename
. ociuldr $USERNAME $PASSWORD $SID ${TMPDIR}/${tablename}.sql ${OUTDIR}/${SCHEMA}/${tablename}.dat ${SCHEMA}_${THREADID} &
let "THREADID+=1"
done
}
######MAIN PROGRAM
start
exit 0
#-[ LICENSE ] -----------------------------------------------------------#
# #
# Scripts Runner Extract Oracle Table Using OCIULDR #
# Copyright (C) 2009 Syahreza Octadian #
# All rights reserved. #
# #
# #
# Permission is granted to anyone to use this software for any purpose, #
# including commercial applications, and to alter it and redistribute #
# it freely, subject to the following restrictions: #
# #
# 1. The origin of this software must not be misrepresented; you must #
# not claim that you wrote the original software. If you use this #
# software in a product, an acknowledgment in the product #
# documentation would be appreciated but is not required. #
# #
# 2. Altered source versions must be plainly marked as such, and must #
# not be misrepresented as being the original software. #
# #
# 3. This notice may not be removed or altered from any source #
# distribution. #
# #
#------------------------------------------------------------------------#
Runner thread script:
#/bin/bash
if [ $# -lt 6 ]
then
echo "Please use arguments, $0 [USERNAME] [PASSWORD] [SID] [SQLFILE] [OUTFILE] [THREAD NAME]"
exit 1
fi
USERNAME=$1
PASSWORD=$2
SID=$3
SQLFILE=$4
OUTFILE=$5
THREADNAME=$6
######THIS IS MANDATORY
######ORACLE LIBRARY
#-[ You must configure this directory ] -----------------------------#
export LD_LIBRARY_PATH=/data01/oradw/oracle/product/10.2.0/Db_1/lib32/:/data01/oradw/oracle/product/10.2.0/Db_1/lib
######OCI PROGRAM
OCI_HOME=/oth02/spoll/oci
######MAIN PROGRAM
echo "" >> ${USERNAME}.log
echo "Start time : `date` $THREADNAME" >> ${USERNAME}.log
echo "Running SQLFILE : ${SQLFILE}" >> ${USERNAME}.log
echo "Running OUTFILE : ${OUTFILE}" >> ${USERNAME}.log
#-[ You must configure oci program ] -----------------------------#
$OCI_HOME/ociuldr_solaris user=${USERNAME}/${PASSWORD}@${SID} sql=${SQLFILE} file=${OUTFILE} field=0x7c >> ${OCI_HOME}/ociuldr_solaris.log
if [ -a ${SQLFILE} ]
then
echo "Removing SQLFILE : ${SQLFILE}" >> ${USERNAME}.log
rm ${SQLFILE}
fi
if [ -a ${THREADNAME}.lock ]
then
rm ${THREADNAME}.lock
fi
echo "End time : `date`" >> ${USERNAME}.log
echo "" >> ${USERNAME}.log
#-[ LICENSE ] -----------------------------------------------------------#
# #
# Scripts Runner Extract Oracle Table Using OCIULDR #
# Copyright (C) 2009 Syahreza Octadian #
# All rights reserved. #
# #
# #
# Permission is granted to anyone to use this software for any purpose, #
# including commercial applications, and to alter it and redistribute #
# it freely, subject to the following restrictions: #
# #
# 1. The origin of this software must not be misrepresented; you must #
# not claim that you wrote the original software. If you use this #
# software in a product, an acknowledgment in the product #
# documentation would be appreciated but is not required. #
# #
# 2. Altered source versions must be plainly marked as such, and must #
# not be misrepresented as being the original software. #
# #
# 3. This notice may not be removed or altered from any source #
# distribution. #
# #
#------------------------------------------------------------------------#
Implementation :
Just configure the scripts such as ORACLE_HOME, LD_LIBRARY_PATH, OCI_HOME, OUT_DIR and TMP_DIR as yours.
To use this scripts you have to download ociuldr software in the official site.
About this entry
You’re currently reading “Extract Oracle Data with OCIULDR,” an entry on Zhobur's
- Published:
- April 21, 2009 / 9:46 am
- Category:
- Oracle PL/SQL, Shell
- Tags:
4 Comments
Jump to comment form | comment rss [?] | trackback uri [?]