Solved

Syntax error in my script

Posted on 2013-05-10
7
471 Views
Last Modified: 2013-05-10
I keep getting this error in my script:

"0403-057 Syntax error at line 6 : `<' is not matched."

I have gotten it before and the problem was EOF statement not being at the very beginning of a line. Not sure what is it this time. here is my script:

#!/usr/bin/ksh

(export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF)|
while read line
do
        if [[ -n $line ]]
                then eval $line
                         printf "[%-10s]\t[%-25s]\t[%-15s]\n" "$fieldid" "$field1" "$field2"
        fi
done

exit 0

Open in new window

0
Comment
Question by:YZlat
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156345
Sorry, I didn't see what you're really after.

I'll be back!
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 275 total points
ID: 39156429
Remove the () parenthesis:
. . . here:
export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. . . .and here:
EOF |\
while read line
do . . .

Open in new window


PS: Notice the back-slash '\' after the pipe '|'
:p
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156432
Generally, you can't place anything into the same line with the terminating EOF, except for a pipe..

You can process the output of preceeding commands along with the output of the "here" document using a pipe in the opening line (the one containing "<<EOF")

However, all processing must be done in one single line, because everything placed into subsequent lines would become part of the "here" document.

Example:

(export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF ) | while read line; do ...; done
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF

Since the line containing "while .. do ... done" could become very long I'd suggest creating a function to process the output.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39156511
Like this:

#!/usr/bin/ksh

function output_fn {
while read line
do
        if [[ -n $line ]]
                then eval $line
                         printf "[%-10s]\t[%-25s]\t[%-15s]\n" "$fieldid" "$field1" "$field2"
        fi
done
}

( export ORACLE_SID=DBNAme
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF ) | output_fn
connect username/pwd
set lines 4000
set trimspool on
set feedback off
set pages 0

  SELECT fieldid, field1, field2 from my_view;
        exit;
EOF

exit 0

Open in new window

Please note that all this would only make sense if you indeed must process the output of the preceeding statement (". oraenv"). Otherwise MikeOM_DBA's solution is the one to use.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39156533
MikeOM_DBA, Thanks!

What does backslash there do? It actually worked without the backslash
0
 
LVL 27

Assisted Solution

by:serialband
serialband earned 25 total points
ID: 39156810
Backslash means continue to the next line as if the newline doesn't exist.  It's used for helping you format long lines into more easily readable paragraphs.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39156866
Thanks!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now