Sometimes getting SP2-0734 error message

Hi All,
Once I try to execute the below script,it will execute the script and it will generate the output file.
Sometimes,it got executed successfully and generate the output file.. sometimes,it got executed and generate the output with error message as

********************************* Top of Data **********************************
SP2-0734: unknown command beginning "PATH=/u01/..." - rest of line ignored.
SP2-0734: unknown command beginning "sqlplus -S..." - rest of line ignored.
******************************** Bottom of Data 
 

Can anyone pls tell me why its showing this error message.[/FONT][/FONT][/COLOR]

Shell script:

SQL_FILE=/ftp/otmtms/config/test.sql
#SID=OTM60APL2D
SID=OAPL2P
RUN_DATE=$(date +%Y%m%d%H%M%S)

function build_sql (){
tempfile=/tmp/.exec_$RUN_DATE
echo "# Set ORACLE_HOME and related variables" > $tempfile
echo "ORACLE_HOME=/u01/app/oracle/product/11.2.0; export ORACLE_HOME" >> $tempfile
echo "LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH; export LD_LIBRARY_PATH" >> $tempfile
echo "NLS_LANG=American_America.UTF8; export NLS_LANG" >> $tempfile
echo "# Set PATH" >> $tempfile
echo "PATH=\$ORACLE_HOME/bin:\$PATH; export PATH" >> $tempfile
echo "sqlplus -S /nolog <<EOF" >> $tempfile
echo "spool /ftp/test/IVin2_OTM_$RUN_DATE.FCNA" >> $tempfile
echo " whenever sqlerror exit FAILURE" >> $tempfile
echo " connect SHIPMAXOWNER/shipmaxowner@$SID " >> $tempfile
echo " @$SQL_FILE" >> $tempfile
echo "EOF" >> $tempfile
#Execute SQL
sh $tempfile
}
build_sql

Sounds like it's running intermittendly, so more context is needed. Are those SQL error msgs? Please post the entire output, contents of variables, tempfile contents...

Thanks Rudic for helping me on this.
I am new to shell script. I will explain you my understanding

1.We placed this shell script in the server. we schedule to run this script daily as cron job.

2.Once the shell scripts runs , I guess it will call test.sql sql file(in the script:SQL_FILE=/ftp/otmtms/config/test.sql) and it will generate the output file
->IVin2_OTM_$RUN_DATE.FCNA(in the script:spool /ftp/test/IVin2_OTM_$RUN_DATE.FCNA) and place it server.
3.lets say, on monday script got executed and placed the file in server WITHOUT ANY ERROR MESSAGE. Next day(tuesday),it got executed and placed the file in the server WITH ERROR MESSAGE.
4.I guess, if there any issue in the script, it supposed to generate the output file with error message on everyday right? But I am getting an error message on alternative days . I guess

can you please provide your feedback on this.

I can't guess. You didn't provide the data requested. You'll need to compare the environments of the two processes to find out what causes the error.