Hi All,
I need to write Unix shell script. To star with : I need to do some file checking on unix file system, then based on file existance, I need to run diff SQL in Teradata Bteq. After that, depending on Results of SQL, I need to code other shell scripting like moving file, within same script.
My script look like:
step1 :- Unix commands...
step2 :- Unix commands...
step3 :- Unix commands...
step4 :- BTeq Login
step5 :- Teradata SQL..
step6 :- BTEQ Logoff
step7 :- Unix Commands..
step8 :- Unix COmmands..
For this I m using code like :
echo 'unix command'
echo 'unix command'
bteq << EOF
.logon <systemid>/<userid>,<password>;
select current_timestamp;
.logoff;
.quit;
EOF
echo 'unix command 3'
echo 'unix command 4'
echo 'unix command 5'
But getting error like:
syntax error: unexpected end of file
But I executed separately shell script and Bteq batch , it is working fine to me.
Please let me Know how to invoke bteq batch in shell script.
Thanks,
Shilpi Gupta
<< EOF
tells it to wait for a line that is exactly "space" "EOF".
Try <<EOF
You'll also get unexpected end of file if you've an if
without fi
or while
without done
, etc... as well as missing quotes. The latter usually prints two errors though in bash:
./script: line 4: unexpected EOF while looking for matching `"'
./script: line 7: syntax error: unexpected end of file
We'll need actual code and actual output to assist further.
Hi Neutronscott,
Please find below code:
clear
DB_FIND()
{
IFS=$'\n'
set -f
echo "=================$BTEQ_NAME=================="
while read i; do
DB_Name=$i
/usr/xpg4/bin/awk -v target=$DB_Name '{for(i=1;i<=NF;i++)if($i ~ target) print $(i)}' $BTEQ_NAME > ${DB_Name}_TableList.txt
sed '/FOLDR/d' ${DB_Name}_TableList.txt > ${DB_Name}_IFile.txt
/usr/xpg4/bin/awk '!x[$0]++' ${DB_Name}_IFile.txt > ${DB_Name}_File.txt
rm ${DB_Name}_IFile.txt
rm ${DB_Name}_TableList.txt
if [ -s ${DB_Name}_File.txt ] ; then
echo ${DB_Name}_File.txt
conn_string=`ksh /apps/cronacle/tools/teradata/.otherdetails/.Info_4ETL.sh UID_ODS_CLP_DRG`
export conn_string;
bteq <<EOF
.logon ${conn_string};
.export report FILE = /ftp/SrcFiles/src/SSSS/sample.txt;
.SET SEPARATOR '|'
SELECT * FROM dbc.tables where tablename='AP_INVC_F_V';
.logoff
.quit;
EOF
fi;
done <Param.txt
}
# Main Body of this Script
BTEQ_NAME_LIST=$1
for i in `cat ${BTEQ_NAME_LIST}` ; do
BTEQ_NAME=`echo "${i}" | awk -F"|" '{ print $1 }'`;
export BTEQ_NAME;
BTEQ_PARAM_FILE=`awk '{for(i=1;i<=NF;i++)if($i~/\/bin/)print $(i)}' $BTEQ_NAME|cut -d"/" -f8|cut -d";" -f1`
awk '{for(i=1;i<=NF;i++)if($i~/\=/)print $(i)}' $BTEQ_PARAM_FILE|cut -d"=" -f1 > ParamP1.txt
awk '{for(i=1;i<=NF;i++)if($i~/_/)print $(i)}' ParamP1.txt > Param.txt
#rm ParamP1.txt
DB_FIND
#rm Param.txt
done
Getting Output as:
./DB_Validation_1.sh: line 66: syntax error: unexpected end of file
This script was working fine, when I m not inserting any Bteq batch inside it..
Please help me to find root cause behind this..
EOF must not have any whitespace before it. There's an exception in bash if you use <<-EOF
.
From Bash Reference Manual: Here Documents :
This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command.
...
If the redirection operator is �<<-�, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.
edit: i see you're calling ksh. <<-
applies to ksh88/93 as well if you decide to indent with tabs.