DB2 Import Unix script with validation
# For bash shell, works on AIX
# It may be required to do a sort before diff in the last command
# This script loads the specified input file to the DB2 table EMP
# and checks the status of the load. It also confirms that the data
# was loaded as expected by exporting back the data from EMP and
# comparing with what is in the input file
if [ !$# -eq 1 ]
then
echo "USAGE: DB2IMPEMP.sh";
exit 1
fi
# Following line picks out the initial part of the extract file name
# passed as input parameter and stores in variable messagefile
# with an extension .msg. Also sets the name of the output file
# to store exported data
messagefile=${1%.*}".msg"
outputfile=${1%.*}".out"
echo $messagefile
echo "Connecting to database..."
db2 connect to nec
echo "...Connected"
retval=`db2 import from $1 of del modified by coldel\| commitcount 0 messages $messagefile replace into EMPLOYEE`
if [ ! -z "$(echo $retval | awk '/SQL.*N/')" ]
then echo "Import error: "$retval;
exit -1;
fi
if [ ! -z "$(echo $retval | awk '/SQL.*W/')" ]
then echo "Import warning: "$retval;
fi
retval=`db2 export to $outputfile of del modified by coldel\| select \* from EMPLOYEE`
compare=`diff $1 $outputfile`
if [ $? -ne 0 ]
then
echo "Data Validation Error";
exit -2;
fi
# It may be required to do a sort before diff in the last command
# This script loads the specified input file to the DB2 table EMP
# and checks the status of the load. It also confirms that the data
# was loaded as expected by exporting back the data from EMP and
# comparing with what is in the input file
if [ !$# -eq 1 ]
then
echo "USAGE: DB2IMPEMP.sh
exit 1
fi
# Following line picks out the initial part of the extract file name
# passed as input parameter and stores in variable messagefile
# with an extension .msg. Also sets the name of the output file
# to store exported data
messagefile=${1%.*}".msg"
outputfile=${1%.*}".out"
echo $messagefile
echo "Connecting to database..."
db2 connect to nec
echo "...Connected"
retval=`db2 import from $1 of del modified by coldel\| commitcount 0 messages $messagefile replace into EMPLOYEE`
if [ ! -z "$(echo $retval | awk '/SQL.*N/')" ]
then echo "Import error: "$retval;
exit -1;
fi
if [ ! -z "$(echo $retval | awk '/SQL.*W/')" ]
then echo "Import warning: "$retval;
fi
retval=`db2 export to $outputfile of del modified by coldel\| select \* from EMPLOYEE`
compare=`diff $1 $outputfile`
if [ $? -ne 0 ]
then
echo "Data Validation Error";
exit -2;
fi

0 Comments:
Post a Comment
<< Home