LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2009, 10:21 PM   #1
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13

Rep: Reputation: 0
Difficulty using "execute immediate" in shell - Sql script


Hello members,

I get an unexpected "end of file" error while trying to execute the following piece of code in the bash / ksh shell. I'm assuming the problem is with using the "execute immediate statement"

Code:
#! /bin/bash

tname="table"

for i in *
do
sqlstr="create table $tname$i as select account_no, balance from records_all"
sqlplus username/password@db_name<<EOF
  execute immediate $sqlstr;
EOF
ksh Error:
+ tname=table
try.ksh[7]: syntax error at line 10 : `<<' unmatched

bash Error:
tname=table
try.sh: syntax error at line 15: `end of file' unexpected

Appreciate your guidance with the correct syntax.

kris
 
Old 10-11-2009, 10:44 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by novice82 View Post
Hello members,

I get an unexpected "end of file" error while trying to execute the following piece of code in the bash / ksh shell. I'm assuming the problem is with using the "execute immediate statement"

Code:
#! /bin/bash

tname="table"

for i in *
do
sqlstr="create table $tname$i as select account_no, balance from records_all"
sqlplus username/password@db_name<<EOF
  execute immediate $sqlstr;
EOF
ksh Error:
+ tname=table
try.ksh[7]: syntax error at line 10 : `<<' unmatched

bash Error:
tname=table
try.sh: syntax error at line 15: `end of file' unexpected

Appreciate your guidance with the correct syntax.

kris
It's not clear whether your script is identical to the original, but one of the few ways this error can come up is if the second EOF is not against the left margin.

On a second look, I see there is a "do" in your script but no "done". Something is seriously wrong with this script. Maybe you should abandon this script and just tell us what the script is supposed to do. Either that you you didn't post the entire script, in which case there's no point in trying to analyze it.
 
Old 10-12-2009, 12:36 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Why not use the techniques we discussed in your previous qn http://www.linuxquestions.org/questi...hlight=sqlplus
 
Old 10-12-2009, 01:09 AM   #4
novice82
LQ Newbie
 
Registered: Oct 2009
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks folks. The following code snippet seems to work for me:
Code:
#! /bin/ksh
tname="table"
for i in temp*
do
    OUTPUT=$(sqlplus -silent username/password@db_name << OK
    set pages 0 feedback off
    create table $tname$i as select account_no, balance from records_all;
OK)
echo " $tname$i table creation is successful "
done
Thanks again!
 
Old 01-16-2010, 02:19 AM   #5
pradeepparamasivam
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
please help me


how to execute .sql file for postgresql database in ubuntu environment without restoring
 
Old 01-16-2010, 02:53 AM   #6
pradeepparamasivam
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
how to give full rights to user for creating and restore database in postgresql
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"URGENT"How can i execute shell script from a remote server ? amit.giri Linux - Newbie 9 10-05-2009 10:15 AM
Getting Shell Script to Execute IF new row in Postgres SQL is added? (PHP) gatorpower Programming 1 03-18-2009 01:45 AM
Not able to execute Oracle Sql command in shell script Ranvijaidba Programming 3 10-23-2008 04:45 PM
converting shell script from "dialog" to "xdialog" kushalkoolwal Programming 1 02-25-2008 09:40 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM


All times are GMT -5. The time now is 06:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration