Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All
I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error.

#!/bin/ksh
#-------------------------------------------------------------------------
# File: ang_stdnld.ksh
#
# Desc: UNIX shell script to extract Store information.
#-------------------------------------------------------------------------
### Set the global variables.
CONNECT=$1
LOG=$MMHOME/log/ang_stdnld_`date +'%b_%d'`.log
ERR=$MMHOME/error/err.ang_stdnld.`date +'%b_%d'`
##SCRIPT_HOME=$MMHOME/oracle/proc/bin
### Check if path where extracts are to be created is passed as arg.
### If this arg is Null, then default to PWD.
if [ "$2" = "" ]
then
DIR=`pwd`
echo "Path is not sent. Defaulting to PWD: "`pwd`
else
if [ -d $2 ]
then
DIR=$2
else
echo "Path $2 does not exist"
exit 1
fi
fi
#-------------------------------------------------------------------------
# Function Name: ang_get_chain()
# Purpose : Create store listing that needs to be processed to
# extract the data.
#-------------------------------------------------------------------------
ang_get_chain()
{
echo "Getting the chain name...\n" >>$LOG
# Set filename to contain this chain 
CHAIN=$DIR/stdnld_chain.lst 
$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF >>$CHAIN
set pause off
set echo off
set heading off
set feedback off
set verify off
set pages 0
select distinct sh.chain
from store st,
store_hierarchy sh,
period p
where st.store = sh.store
and p.vdate between st.store_open_date and nvl(st.store_close_date,p.vdate)
order by chain;
EOF 
if [ `grep "^ORA-" $CHAIN | wc -l` -gt 0 ]
then
cat $CHAIN >> $ERR
remove_files
echo "ORA Error while creating Chain listing in ang_get_chain()." >> $LOG
exit 1
fi
for i in `cat $CHAIN`
do
returnedchainvalue=`$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF
set serveroutput on;
set pause off
set echo off
set heading off
set feedback off
set verify off
set pages 0
Declare
message VARCHAR2(200);
Begin
select ANGELIC_PKG.ANG_GET_CHAIN_NAME($i) into message from dual;
dbms_output.put_line (message);
End;
/
set serveroutput off;
EXIT;
EOF` 
X=`echo $returnedchainvalue` 
$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF >>${X}_en-us_stores_001
SELECT S.STORE, 
S.STORE_NAME, 
S.PHONE_NUMBER, 
A.ADD_1, 
A.ADD_2, 
A.CITY, 
A.STATE, 
A.POST, 
A.COUNTRY_ID, 
'HOMEPAGE', 
'HOURS', 
'CATEGORY', 
'DESCRITPION', 
S.CURRENCY_CODE, 
S.STORE_OPEN_DATE, 
'LATITUDE', 
'LONGITUDE'
FROM STORE S, 
ADDR A, 
STORE_HIERARCHY SH
WHERE A.MODULE='ST'
AND A.COUNTRY_ID='US'
AND A.KEY_VALUE_1=S.STORE
AND A.ADDR_TYPE=01
AND S.STORE=SH.STORE
AND SH.CHAIN=$i;
EOF
done
}
#-------------------------------------------------------------------------
# Function Name: remove_files()
# Purpose : Clean the temporary files created.
#-------------------------------------------------------------------------`
remove_files()
{
echo "Removing temporary files...\n" >> $LOG
# Clean up temp list files.
rm -f $CHAIN_LIST
if [[ -s $ERR ]]
then
:
else
rm -f $ERR
fi
return 0
}
### end remove_files

Can somebody please help me understand as why am i getting this error and how possibily can i troubleshoot it.
As I am currently working on a project, hence a quick response is highly appreciated.
Thanks in advance for the help...

Thanks
Amit

Hi.

As silly as it sounds, you have a space after EOF. You need to remove it.

#!/bin/ksh
#-------------------------------------------------------------------------
# File: ang_stdnld.ksh
#
# Desc: UNIX shell script to extract Store information.
#-------------------------------------------------------------------------
### Set the global variables.
CONNECT=$1
LOG=$MMHOME/log/ang_stdnld_`date +'%b_%d'`.log
ERR=$MMHOME/error/err.ang_stdnld.`date +'%b_%d'`
##SCRIPT_HOME=$MMHOME/oracle/proc/bin
### Check if path where extracts are to be created is passed as arg.
### If this arg is Null, then default to PWD.
if [ "$2" = "" ]
then
DIR=`pwd`
echo "Path is not sent. Defaulting to PWD: "`pwd`
else
if [ -d $2 ]
then
DIR=$2
else
echo "Path $2 does not exist"
exit 1
fi
fi
#-------------------------------------------------------------------------
# Function Name: ang_get_chain()
# Purpose : Create store listing that needs to be processed to
# extract the data.
#-------------------------------------------------------------------------
ang_get_chain()
{
echo "Getting the chain name...\n" >>$LOG
# Set filename to contain this chain 
CHAIN=$DIR/stdnld_chain.lst 
$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF >>$CHAIN
set pause off
set echo off
set heading off
set feedback off
set verify off
set pages 0
select distinct sh.chain
from store st,
store_hierarchy sh,
period p
where st.store = sh.store
and p.vdate between st.store_open_date and nvl(st.store_close_date,p.vdate)
order by chain;
EOF 
if [ `grep "^ORA-" $CHAIN | wc -l` -gt 0 ]
then
cat $CHAIN >> $ERR
remove_files
echo "ORA Error while creating Chain listing in ang_get_chain()." >> $LOG
exit 1
fi
for i in `cat $CHAIN`
do
returnedchainvalue=`$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF
set serveroutput on;
set pause off
set echo off
set heading off
set feedback off
set verify off
set pages 0
Declare
message VARCHAR2(200);
Begin
select ANGELIC_PKG.ANG_GET_CHAIN_NAME($i) into message from dual;
dbms_output.put_line (message);
End;
/
set serveroutput off;
EXIT;
EOF` 
X=`echo $returnedchainvalue` 
$ORACLE_HOME/bin/sqlplus -s $CONNECT <<EOF >>${X}_en-us_stores_001
SELECT S.STORE, 
S.STORE_NAME, 
S.PHONE_NUMBER, 
A.ADD_1, 
A.ADD_2, 
A.CITY, 
A.STATE, 
A.POST, 
A.COUNTRY_ID, 
'HOMEPAGE', 
'HOURS', 
'CATEGORY', 
'DESCRITPION', 
S.CURRENCY_CODE, 
S.STORE_OPEN_DATE, 
'LATITUDE', 
'LONGITUDE'
FROM STORE S, 
ADDR A, 
STORE_HIERARCHY SH
WHERE A.MODULE='ST'
AND A.COUNTRY_ID='US'
AND A.KEY_VALUE_1=S.STORE
AND A.ADDR_TYPE=01
AND S.STORE=SH.STORE
AND SH.CHAIN=$i;
EOF
done
}
#-------------------------------------------------------------------------
# Function Name: remove_files()
# Purpose : Clean the temporary files created.
#-------------------------------------------------------------------------`
remove_files()
{
echo "Removing temporary files...\n" >> $LOG
# Clean up temp list files.
rm -f $CHAIN_LIST
if [[ -s $ERR ]]
then
:
else
rm -f $ERR
fi
return 0
}
### end remove_files

Hi
First of all Thank You so much... for the help...
it really worked... the script ran without any errors...
but there s new problem now.
it is suppose to create some files as an output.
it is not doing so... infact i had put some echo commands and tested.
it is not getting inside the function 'ang_get_chain()' .

Thanks again for the help... really appreciate it...

Thanks so much...
Amit

Hi.

As silly as it sounds, you never call the function :slight_smile:

1 Like