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 [ 0 -eq $(ls verify_inbound_failed.txt | wc -l) ]
then
sqlplus -s /nolog <<EOF
connect $db_username/$db_password@$db_sid
exec pr_od_lp_override();
exit
EOF
fi

Thanks in advance
Vinay

Did you use a dos/windows editor?

here am using Textpad.
is it going to differ by editors?
its urgent,, can you pls help me,,,,

Dos/windows editors add a CR at the end of the line, remove them with:

tr -d '\n' < file > newfile
mv newfile file

here the problem is , same code works fine with no error if it is not there in "if" block. as i have shown above.

Have you removed the CRs from your file?

Have tou tried this ???

if [ 0 -eq $(ls verify_inbound_failed.txt | wc -l) ]
then
sqlplus -s /nolog <<EOF
connect $db_username/$db_password@$db_sid
exec pr_od_lp_override();
exit
fi
EOF

can you please tell me what is the file and newfile ?
is the syntax or we need to create a new file ?

i am new to this field, can you please elaborate it, so i can do the same.

i tried in both ways, its not working :confused:

This command removes the CRs from file and redirects the output to a file with the name newfile:

tr -d '\n' < file > newfile

This command mv (renames) the file newfile to file:

mv newfile file

Replace the name file with the name of your file in both commands.

Do you want to check if "verify_inbound_failed.txt" exist ???

Though probably not the cause of the unexpected eof (depends which shell you are using), the first line will fail if the file does not exist. I assume you want to run sqlplus if the file does not exist.

Try:

if [ 0 -eq $(ls verify_inbound_failed.txt 2>/dev/null | wc -l) ]

Or much better:

if [ ! -f verify_inbound_failed.txt ]

Of if you actually wanted to run sqlplus if the file has lines in it.

if [ -s verify_inbound_failed.txt ]

still getting the same error :confused:
is there any other way to solve this issue ?