Can not determine end-of-file error

Hello Experts,

I've used vi editor to write this script, provided permission, but I invoke it
it is prompting end-of-file errors.. I'm not sure what is causing that error..
would like some help.. I've attached details..

perseus.gasleak(/tmp/v_tst)% ls -l f2.sh
-rwxr-xr-x   1 gasleak       393 Feb 15 14:12 f2.sh
perseus.gasleak(/tmp/v_tst)% cat f2.sh
#!/bin/sh
#. /u01/app/oracle/local/bin/cron_env_$ORACLE_SID
file_name='./services.dat'
     if [ -f $file_name ]; then
       echo "file found " $file_name
       sqlplus /nolog <<EOF >./tst.log
       connect test/test
         set feedback off
         set echo on
         @./glspreltr.sql
       exit
       EOF
      fi
       mv $file_name $file_name_%m%d%Y
#       echo $file_name
perseus.gasleak(/tmp/v_tst)%
perseus.gasleak(/tmp/v_tst)% ./f2.sh
./f2.sh: syntax error at line 16: `end of file' unexpected
perseus.gasleak(/tmp/v_tst)%

Without digging deeper: Try opening the here documwent with <<- to allow for <TAB> indentation of the EOF token.

if you meant this .. I tried .. still same error

 sqlplus /nolog <<-EOF >./tst.log

Is the EOF really indented with a / some <TAB> s, NOT spaces?

my intent for that line is to invoke sqlplus , write log activities to a specific file name and call a script, which is executing two PL/Sql stored procedures..

I believe that is what I did ..

I wasn't challenging your intentions, but asking if that respective line's indentation uses <TAB> characters.

for "indentation" sake I've used spaces..
is that the issue?

Yes. That is an issue. The here-document started with the line:

       sqlplus /nolog <<EOF

does not end until there is a line that just contains the three characters EOF and a line terminating <newline> character. If you started the here document with <<-EOF instead of <<EOF , the here-document could be terminated by a line just containing zero or more leading <tab> characters, the three characters EOF , and a line terminating <newline> character. Any <space> characters before the here-document terminator string will cause that line to included in the here-document and keep it from being recognized as the terminator.

1 Like

Try:-

Remove the indent on line #12 to place the EOF token at the beginning of the line.

ok.. to test further, I've removed all of the spaces and used <<EOF>> tag as suggested. I'v also used db connection login/pw.. this time it didn't prompt end-of-file error.. but file rename didn't work..
if I could I've two follow-up questions -

#!/bin/sh
#. /u01/app/oracle/local/bin/cron_env_$ORACLE_SID
file_name='./services.dat'
if [ -f $file_name ]; then
echo "file found " $file_name
sqlplus /nolog <<-EOF >./tst.log
connect test/test
set feedback off
set echo on
@./glspreltr.sql
exit
EOF
fi
mv $file_name $file_name_%m%d%Y
echo $file_name

output:
perseus.gasleak(/tmp/v_tst)% ./f2.sh
file found ./services.dat
./services.dat

qes1: in the file rename some how did not like "%m%d%Y" format.. why?
qes2: is there way to determine when the file was written mm-dd-yy-hh-mm and use that for the rename. if so, please suggest how to do that.

As you are using /bin/sh you need to use the date program:

mv "${file_name}" "${file_name}"_$(date +'%m%d%Y')

You can get hold of the access time, modification time and change time of a file using stat if you have it:

stat -c "%y" "${file_name}" 

Gnu date also has a switch to show the last modification timestamp of a file:

date -r "${file_name}"

which is probably the closest you will get on a Linux/Unix system to the creation time. So you could possibly use:

mv "${file_name}" "${file_name}"_$(date -c "${file_name}"  +'%m%d%Y')

Not really, not reliably, especially with only two-digit years.

yes I'm using "/bin/sh "

it won't let me use stat .. it prompts "not found..
also, I could not use switch with stat and also -r switch with date
the closet I can try was that

mv "${file_name}" "${file_name}"_`date +'%m%d%Y'`

at least this time renamed the file with date stamp..

Appreciate all your help. It is helping me learn shell scripting

You could try my general purpose date script written in perl which supports many GNU date like options.