Unexpected end of file error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unexpected end of file error
# 1  
Old 12-29-2010
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 !!!
Code:
 
#!/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


Last edited by Scott; 12-29-2010 at 03:56 AM.. Reason: Please use code tags
# 2  
Old 12-29-2010
Try replacing
Code:
<< EOF

by
Code:
<<-EOF

and make sure the ending delimiter (EOF) is prefixed by tabs, not spaces.
# 3  
Old 12-29-2010
I tried the code change but still getting the same error .
# 4  
Old 12-29-2010
Did you change both of the here document mistakes ?

There is also a wrong syntax here, although unreleated to the end of file error:
Code:
if [[ wc -l ./$table_nm.bcp.txt != 0 ]]

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

# 5  
Old 12-29-2010
I believe that in "here-document", end line of "here-document" delimeter should start from 1st column (No space/tab before that).
Code:
        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.
Code:
        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:
Code:
if [[ $(wc -l ./$table_nm.bcp.txt) != 0 ]]

# 6  
Old 12-29-2010
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

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!!!!

Last edited by Franklin52; 12-29-2010 at 10:08 AM.. Reason: Please use code tags
# 7  
Old 12-29-2010
Quote:
Originally Posted by anurag.singh
Two corrections here
1. No space between << and EOF
2. AT the end, EOF should have no tab/space before it
To preserve indenting, a better solution is to use, as I already suggested,
Code:
....   <<-EOF # note the extra dash

and have the ending EOF properly indented with tabs.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unexpected End of File Syntax Error

Hi, I am brand new to this so I apologize ahead of time for any formatting problems. I know there is a previous (closed) thread on here about this problem but I wasn't able to fix the error following the posts there so I thought I could create a new one. Here is the error I am getting: ... (3 Replies)
Discussion started by: SierraG
3 Replies

2. Shell Programming and Scripting

Unexpected End Of File Error

Hi guys, I am new to BASH scripting and I was wondering if anyone could have a look at this code and explain to me why I am getting an Unexpected End of File Error ? If you can that would be great / much appreciated! THANKS! #!/bin/bash USER="" PASS="" if ; then echo "You need to set... (1 Reply)
Discussion started by: spooke
1 Replies

3. Shell Programming and Scripting

syntax error unexpected end of file

I am new to unix, so thank u for ur patience I try to make it work (to duplicate two first columns in several files): #!/bin/bash for i in `seq 2 5` do awk `{ print $1,$1,$2,$2,$3,$4}` final_chr.${i} > input_${i} done and i get ./my_script3.sh: command substitution: line 5: syntax... (2 Replies)
Discussion started by: kush
2 Replies

4. Shell Programming and Scripting

`end of file' unexpected error

When I am executing my really simple shell script below, I got an error: `end of file' unexpected. Script is suppose to print out a list of supplied parameters. Here is my script: #!/bin/sh a=$# #number or parameters b=0 #starting counter while do b=`expr $b + 1` echo... (9 Replies)
Discussion started by: alexstar
9 Replies

5. Shell Programming and Scripting

error unexpected end of file

Sometimes while unziping some files i got an error and the further unziping stopped.might be other files are able to be unzip.i.e gunzip a.Z b.Z c.Z gunzip: a.Z: unexpected end of file it found an error on a.Z and stopped but b.Z and C.Z might be correct. why this error comes and is... (2 Replies)
Discussion started by: malikshahid85
2 Replies

6. Shell Programming and Scripting

syntax error: unexpected end of file

Hi, I am newbie to UNIX scripting. I am facing this error "syntax error: unexpected end of file" while executing the following script: ------ a=$1 if then sqlplus -s prospect_stg/prospect_stg@mdmpt <<END insert into bckup_marc_parameter_lookup select * from... (6 Replies)
Discussion started by: boopathyvasagam
6 Replies

7. Shell Programming and Scripting

unexpected end of file error

When I run the following script: #! /bin/bash for var in CA CC CD CT EC PC do cat << EOF > ${var}_full.dat echo T ${var}_high echo C age echo C sex echo C ht echo C WT_lg EOF cat << EOF > ${var}_agesex.dat ... (4 Replies)
Discussion started by: polly_falconer
4 Replies

8. Shell Programming and Scripting

unexpected end of file error

hi, i am trying to connect to sqlplus in an 'if block' from the script. it is giving unexpected end of file error. and it works fine if it is out of 'if block'. if anybody have idea on this, can you please help me to solve the error ? piece of code is given below. if then... (11 Replies)
Discussion started by: vinayakatj56
11 Replies

9. Shell Programming and Scripting

syntax error: unexpected end of file

Hi, I need ur help is this matter, i have th ebelow script, and i keep getting this error: syntax error: unexpected end of file affectedRow=`cat dbOutput.log | grep "1 row affected"` echo "affectedRow : $affectedRow" if ; then echo "Look to the next OMCDB" ... (10 Replies)
Discussion started by: Alaeddin
10 Replies

10. Shell Programming and Scripting

End of file unexpected error

Hi, I am new to unix. I have written a script whenever i am giving sh filename.sh its prompting unexpected end of file in line number 40 in that line i have echo statement what do i need to do thanks in advance (5 Replies)
Discussion started by: hamsa
5 Replies
Login or Register to Ask a Question

Featured Tech Videos