0

here I'm trying to run a normal query with sqlplus and dump the result into CSV file, then I have another job to do, I facing problem my script does not continue after executing sqlplus query it just views the result and dumps the output into csv file but it does not continue also i don't know how to dump the data without view the result out

#!/bin/bash

cd /dir/test_dir

    sqlplus -s test/test <<EOF
    set colsep ,
    set underline off,
    set headsep off,
    set feedback off,
    set long 99999,
    set linesize 32767,
    set trimspool on,
    spool report(date +%Y-%m-%d).csv
    select a.s, a.d, a.t, a.ww, a.tt from test a;
    exit;
    EOF
cd ../

mkdir test/
.
.
.

1 Answers1

1

The line containing EOF with leading blanks does not terminate the here document started with <<EOF. Use EOF without leading blanks. Instead of

    EOF

you should use

EOF

Alternatively change the line with redirection to sqlplus -s test/test <<-EOF and then indent with tabs.

If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.

(source)

  • 1
    They may also want to quote the query to prevent the shell from doing expansion in it (not really an issue in the code that they are currently showing), with <<-'EOF'. – Kusalananda Mar 21 '20 at 18:43