Unexpected end of file error

Hi ,
I am new to Unix and this is my first shell script .
I am facing "unexpected end of file error" while executing my code . tried removing blank spaces Unable to trace out the error . PLease help !!!

 
#!/bin/sh
echo hello
 if [[ "$1"  =  '' ]]
 echo hi
 then
        var=`cat liq_table_nm.txt`
        for table_nm in $var;
    do
        echo $table_nm
        echo enter loop
        bcpout_data()
        {
        $bcp liqdb..$table_nm out ./$table_nm.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        }
        delete_table()
        {
        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8'<< EOF
        use liqdb
        go
        if exists ( select 1 from sysobjects where type = 'U' and name = $table_nm)
        delete from liqdb..$table_nm
        go
        EOF
        }
        bcpin_data()
        {
        if [[ wc -l ./$table_nm.bcp.txt != 0 ]]
        then
        $bcp liqdb..$table_nm in ./$table_nm.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        fi
        }
        bcpout_data "$1"
        #delete_table
        bcpin_data
        rm -f ./$table_nm.txt
        echo "Creating log files....."
        ${LOGDIR}/test_automate.log
      done
else
        bcpout_histdata()
        {
        $bcp "select * from liqdb_hist..alm_tran_fact_core_hist where alm_rpt_dt='$1'" queryout
alm_tran_fact_core_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        
$bcp "select * from liqdb_hist..transaction_info_hist where upd_bus_dt='$1'" queryout
transaction_info_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..e2k_account_balance_hist where upd_bus_dt='$1'" queryout
e2k_account_balance_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..currency_rate_hist where upd_bus_dt='$1'" queryout
currency_rate_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..liq_process_dt_hist where upd_bus_dt='$1'" queryout
liq_process_dt_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        }
        delete_histtable()
        {
        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8'<< EOF
  use liqdb
        go
        delete from liqdb..alm_tran_fact_core
        delete from liqdb..transaction_info
        delete from liqdb..e2k_account_balance
        delete from liqdb..currency_rate
        delete from liqdb..liq_process_dt
        go
        EOF
        }
        bcpin_histdata()
        {
        $bcp liqdb..alm_tran_fact_core_hist in alm_tran_fact_core_hist.bcp.txt  -S'MSNYCLRTD01' -U'liqadm'
-P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..transaction_info_hist in transaction_info_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8'
-c -b1000 -t'\|'
        $bcp liqdb..e2k_account_balance_hist in e2k_account_balance_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm'
-P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..currency_rate_hist in currency_rate_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c
-b1000 -t'\|'
        $bcp liqdb..liq_process_dt_hist in liq_process_dt_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c
-b1000 -t'\|'
        }
        bcpout_histdata "$1"
        #delete_histtable
        bcpin_histdata
        echo Remove files
        rm -f alm_tran_fact_core_hist.bcp.txt
        rm -f transaction_info_hist.bcp.txt
        rm -f e2k_account_balance_hist.bcp.txt
        rm -f currency_rate_hist.bcp.txt
        rm -f liq_process_dt_hist.bcp.txt
        echo "Creating log files....."
        ${LOGDIR}/test_automate.log
fi

Try replacing

<< EOF

by

<<-EOF

and make sure the ending delimiter (EOF) is prefixed by tabs, not spaces.

I tried the code change but still getting the same error .

Did you change both of the here document mistakes ?

There is also a wrong syntax here, although unreleated to the end of file error:

if [[ wc -l ./$table_nm.bcp.txt != 0 ]]

should be:

if [ $(wc -l ./$table_nm.bcp.txt) != 0 ]

I believe that in "here-document", end line of "here-document" delimeter should start from 1st column (No space/tab before that).

        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8'<< EOF
        ---------YOUR LINES------------
        ---------YOUR LINES-----------
        EOF

Two corrections here

  1. No space between << and EOF
  2. AT the end, EOF should have no tab/space before it
    i.e.
        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8'<<EOF
        ---------YOUR LINES------------
        ---------YOUR LINES-----------
EOF

Both of your "here-document" need to be corrected as above.
Also your if condition should be:

if [[ $(wc -l ./$table_nm.bcp.txt) != 0 ]]

Thanks for pointing out the mistake but still the error is the same . what do u mean by the 'here document mistakes'??

I have made few changes in the code and it looks like this .Pls let me know what to do ...

Code

#!/bin/sh
#############################################################################
#shell Script to do a complete refresh of table data from ODS schema       #
#PROMPTS FOR THE PRODUCTION AND QA SERVER NAME USER NAME AND PASSWORD      #
#############################################################################
#liq_table_nm.txt is the file name in which the table names will be stored for ODS schema
set -x on
if [[ 1$1 = 1 ]] #If parameter is null
 then
        echo Inside
        var=`cat liq_table_nm.dat`
       for table_nm in $var
      do
        echo $table_nm
        echo enter loop
        bcpout_data()
        {
        $bcp liqdb..$table_nm out ./$table_nm.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        }
         delete_table()
        {
        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' << EOF
        use liqdb
        go
        if exists ( select 1 from sysobjects where type = 'U' and name = $table_nm)
         delete from liqdb..$table_nm
        go
        EOF
        }
        bcpin_data()
        {
        if [ $(wc -l ./$table_nm.bcp.txt) != 0 ]
        #if [[ $count != 0 ]]
        then
        $bcp liqdb..$table_nm in ./$table_nm.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        fi
        }
        bcpout_data "$1"
        #delete_table
        bcpin_data
        rm -f ./$table_nm.txt
        echo "Creating log files....."
        #${LOGDIR}/test_automate.log
      done
else
        bcpout_histdata()
        {
        $bcp "select * from liqdb_hist..alm_tran_fact_core_hist where alm_rpt_dt='$1'" queryout alm_tran_fact_core_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..transaction_info_hist where upd_bus_dt='$1'" queryout transaction_info_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..e2k_account_balance_hist where upd_bus_dt='$1'" queryout e2k_account_balance_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..currency_rate_hist where upd_bus_dt='$1'" queryout currency_rate_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..e2k_account_balance_hist where upd_bus_dt='$1'" queryout e2k_account_balance_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..currency_rate_hist where upd_bus_dt='$1'" queryout currency_rate_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        $bcp "select * from liqdb_hist..liq_process_dt_hist where upd_bus_dt='$1'" queryout liq_process_dt_hist.bcp.txt -S'MSNYCLRTP01' -U'liqadm' -P'liqCRSP)0' -c -b1000 -t'\|'
        }
#<<'END1'  # This is for block commenting
        delete_histtable()
        {
        isql -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' << EOF
        use liqdb
        go
        delete from liqdb..alm_tran_fact_core
        delete from liqdb..transaction_info
        delete from liqdb..e2k_account_balance
        delete from liqdb..currency_rate
        delete from liqdb..liq_process_dt
        go
        EOF
        }
#END1  # block commenting ends here
        bcpin_histdata()
        {
        $bcp liqdb..alm_tran_fact_core_hist in alm_tran_fact_core_hist.bcp.txt  -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..transaction_info_hist in transaction_info_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..e2k_account_balance_hist in e2k_account_balance_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..currency_rate_hist in currency_rate_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        $bcp liqdb..liq_process_dt_hist in liq_process_dt_hist.bcp.txt -S'MSNYCLRTD01' -U'liqadm' -P'liqCRSD)8' -c -b1000 -t'\|'
        }
        bcpout_histdata "$1"
        #delete_histtable
        bcpin_histdata
        echo Remove files
        rm -f alm_tran_fact_core_hist.bcp.txt
        rm -f transaction_info_hist.bcp.txt
        rm -f e2k_account_balance_hist.bcp.txt
        rm -f currency_rate_hist.bcp.txt
        rm -f liq_process_dt_hist.bcp.txt
        echo "Creating log files....."
        #${LOGDIR}/test_automate.log
set -x off
fi
 

---------- Post updated at 04:26 AM ---------- Previous update was at 04:11 AM ----------

Thank You all for your help.. Code worked!!!!

To preserve indenting, a better solution is to use, as I already suggested,

....   <<-EOF # note the extra dash

and have the ending EOF properly indented with tabs.