Spool in Shell script not working for me #!/bin/sh

echo "Started at" `date +%Y/%m/%d" "%H:%M:%S`

sqlplus -s ${ORA_LOGIN_SYSADM} &lt;&lt;EOF 2&gt;&amp;1 &gt; /dev/null
SET SERVEROUTPUT ON
SET FEED OFF
spool ech.txt create
BEGIN
DBMS_OUTPUT.PUT_LINE('xyz');
END;
/
spool off
EOF


if [ $? -ne 0 ]
then
   echo " ech.sh sql   Error"
   exit 1
else
   echo " ech.sh  Successful"
fi


I am getting an SQL error message. Any ideas?
I took some code snippets from a backup script that I use. 
You can redirect all output with the exec command, then 
redirect it back. You can also surround everything with 
braces and redirect that to a log file.

Personally I think bash is a better shell to program in, 
if you don't have bash ksh works too.

#!/bin/bash

export MY_LOG_FILE=my_log_file.log

exec &gt;${MY_LOG_FILE}
exec 2&gt;&amp;1

export ORACLE_BASE=/home/oracle/admin
export ORACLE_HOME=/software/oracle/product/11.2.0
export TNS_ADMIN=${ORACLE_HOME}/network/admin
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
export ORACLE_SID=mysid


echo "Started at" `date +%Y/%m/%d" "%H:%M:%S`

sqlplus -s ${ORA_LOGIN_SYSADM} &lt;&lt;EOF
SET SERVEROUTPUT ON
SET FEED OFF
BEGIN
   DBMS_OUTPUT.PUT_LINE('xyz');
END;
/
EOF

exec 1&gt;&amp;-
exec 2&gt;&amp;-
exec &gt;/dev/tty
exec 2&gt;&amp;1

if [ `egrep -n "ORA-|RMAN-" ${MY_LOG_FILE}` -ne 0 ]
then
   echo " ech.sh sql   Error"
   egrep -n "ORA-|RMAN-" ${MY_LOG_FILE}
   exit 1
else
   echo " ech.sh  Successful"
fi