Solved

Syntax error in my script

Posted on 2013-05-10
7
475 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 29

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

832 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