Here document and shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Here document and shell scripting
# 1  
Old 02-24-2010
Here document and shell scripting

Hi

I am unable to spot a error with my here document in the shell script.

Code:
for sid in $sids
do
    ORACLE_SID=sid
    ORACLE_HOME=$(grep $sid $ORATAB_LOC |cut -f2 -d':')
    $ORACLE_HOME/bin/sqlplus -s /nolog <<EOF
    @$HOME/sql/checkdb-status.sql
EOF
done


I am getting the error with korn shell
Syntax error at line 5: `<' is not matched

Any ideas what i am doing wrong

regards

xiamin
# 2  
Old 02-24-2010
xiamin,

Is this a typo?

Code:
ORACLE_SID=sid

Should be:

Code:
ORACLE_SID=$sid

# 3  
Old 02-24-2010
Btw. The error message you post did not come from executing the script you posted. Please post the complete script (hiding any passwords or confidential data).

What is in these environment variables?

$sids
$ORATAB_LOC

Is every entry in $sids completely unique within oratab ? The grep is quite fuzzy and could you get more than one line back?

You don't need the here document

Quote:
$ORACLE_HOME/bin/sqlplus -s /nolog <<EOF$
@$HOME/sql/checkdb-status.sql$
EOF$


It can be done on the sqlplus command line:

Code:
    $ORACLE_HOME/bin/sqlplus /NOLOG @$HOME/sql/checkdb-status.sql

The first line of @$HOME/sql/checkdb-status.sql should be
connect username/password ;
And the last line should be
quit;


Last edited by methyl; 02-24-2010 at 09:44 AM.. Reason: Omitted to request actual script. Fun with layout.
# 4  
Old 02-24-2010
Hi

This is the complete script.


Code:
#!/bin/ksh

if ! get_oratab_loc  ; then
  echo "Unable to determine Oratab directory"
  exit 1
fi


sids=$(grep "^[^#+]" $ORATAB_LOC|cut -f1 -d':')

for sid in $sids
do
    ORACLE_SID=$sid
    ORACLE_HOME=$(grep $sid $ORATAB_LOC |cut -f2 -d':')
    echo $ORACLE_HOME $ORACLE_SID
    $ORACLE_HOME/bin/sqlplus -s /nolog <<EOF
    @$HOME/sql/checkdb-status.sql
    EOF
done

I corrected the $sid stuff but still i have the same error of

Syntax error at line 18 : `<' is not matched
# 5  
Old 02-24-2010
Your complete script is different from the original post in one important aspect: your original script has the 'EOF' marker on the first column, as it should be, while in your complete script it is indented. Move it out, and it should work as expected.
# 6  
Old 02-24-2010
Hi

Not sure but this started working

Code:
for sid in $sids
do
    ORACLE_SID=$sid
    ORACLE_HOME=$(grep $sid $ORATAB_LOC |cut -f2 -d':')
    echo $ORACLE_HOME $ORACLE_SID
    $ORACLE_HOME/bin/sqlplus -s  << EOF
    @$HOME/sql/checkdb-status.sql
EOF
done

only change is indentation of the closing EOF i am baffled why this works
(it is almost behaving like python )
# 7  
Old 02-24-2010
EOF must be in column 1.
I have not used sqlplus, but maybe sql file is argument, not stdin ?
Code:
for sid in $sids
do
    ORACLE_SID=$sid
    ORACLE_HOME=$(grep "$sid" $ORATAB_LOC |cut -f2 -d':')
    echo $ORACLE_HOME $ORACLE_SID
    $ORACLE_HOME/bin/sqlplus -s /nolog <<EOF
    @$HOME/sql/checkdb-status.sql
EOF
done


Code:
sqlplus   @some.sql
#or
sqlplus <<EOF
$( cat some.sql )
EOF
#or
sqlplus <<EOF
somesql;
cmd2;
quit;
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Shell Script to Remove MongoDB Document-Based on Many inputs

Here I am in a position to write a Unix Shell script(.sh) to remove MongoDB collection documents. I know how to remove based on a condition like below and it works for me. eval 'db.Collection.remove({TimeStamp:{$lte: "'$var'"}}) But I need to change the remove statement based on a new parameter... (1 Reply)
Discussion started by: senthilmadhanT
1 Replies

2. Shell Programming and Scripting

HERE Document in Shell Script

Hi, I have a shell script to install one of our products. It comprises of commands that are specific to the product installation. These commands require user inputs at different stages. To avoid manual feeding of inputs every time, I tried using HERE document. it is like- #! /usr/bin ... (1 Reply)
Discussion started by: nishant.kansal@
1 Replies

3. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

4. Shell Programming and Scripting

Oracle Shell script | here document `EOF' unclosed

Hi folks I m creating script which is give me below error. $ ./function.ksh ./function.ksh: here document `EOF' unclosed Inside the script is #!/bin/ksh export ORACLE_SID=OECDV1 export ORACLE_HOME=/u01/app/oracle/product/10.2.0 export PATH=$ORACLE_HOME/bin:$PATH echo "sql is... (3 Replies)
Discussion started by: tapia
3 Replies

5. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

6. UNIX for Dummies Questions & Answers

Need Shell Script for document searching

I need a script that reads only printable characters (no duplicates) from all files in a directory and output them in a text file. (2 Replies)
Discussion started by: l20N1N
2 Replies

7. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

8. Shell Programming and Scripting

Shell Scripted Document Management System

Over the past 4 -5 years, I have cobbled together a rudimentary 'Document Management System' for a school district I support using Linux Bash Shell scripts.. The purpose of the scripting was to supplement features of a Job Applicant Center that had very simplistic methods of handle file... (1 Reply)
Discussion started by: rmuledeer
1 Replies

9. Programming

UNIX Shell Script to Create a Document of a PLSQL code.

Hi All, I am supposed to present the documentation for the PLSQL code (PACKAGES, PROCEDURE, FUNCTIONS) of my application. There are sufficient comments in my code. Has anyone written any Shell Script Utility which can parse the PLSQL code and generate some kind of document ( preferrably HTML not... (1 Reply)
Discussion started by: gauravsachan
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question