[Solved] While loop error when add sqlplus command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] While loop error when add sqlplus command
# 1  
Old 10-29-2013
[Solved] While loop error when add sqlplus command

Hi gurus,

I hit a block when write the script.

I need do while loop, in the loop I have code below.
Code:
sqlplus -s abc/abc@abc <<EOF
spool testwhile
select *
from dual;
spool off
exit;
EOF

when I run script with only this code, it works fine.
if I add code as below:
Code:
#!/bin/ksh

while :
do
sqlplus -s abc/abc@abc <<EOF
spool testwhile
select *
from dual;
spool off
exit;
EOF
sleep 10
done

I got error:
Code:
syntax error at line 5 : `<<' unmatched

Code:
 1  #!/bin/ksh

     2  while :
     3  do
     4  sqlplus -s EDSETL/edsetl11@EDR1D <<EOF
     5  spool testwhile
     6  select *
     7  from dual;
     8  spool off
     9  exit;
    10  EOF
    11  sleep 10
    12  done

Anybody can help me this?

Any input is very welcome

thanks in advance.
# 2  
Old 10-29-2013
I suspect that, in putting it in a while loop, you indented the final EOF, which you cannot do. It must be at the beginning of the line.
# 3  
Old 10-29-2013
Quote:
Originally Posted by Corona688
I suspect that, in putting it in a while loop, you indented the final EOF, which you cannot do. It must be at the beginning of the line.
Thanks for your reply.

since I am very new for unix, would you please give me an example. Thanks
# 4  
Old 10-30-2013
I don't think there is issue with your script, Please make sure you don't have space (white space) after EOF
This User Gave Thanks to kunal37 For This Post:
# 5  
Old 10-30-2013
This is good:

Code:
cat <<EOF
a
b
c
d
e
EOF

This is bad:

Code:
cat <<EOF
a
b
c
d
e
        EOF

This User Gave Thanks to Corona688 For This Post:
# 6  
Old 11-01-2013
Quote:
Originally Posted by Corona688
This is good:

Code:
cat <<EOF
a
b
c
d
e
EOF

This is bad:

Code:
cat <<EOF
a
b
c
d
e
        EOF

Thank you very much, this is resolves my problem.

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

2. Shell Programming and Scripting

[Solved] FOR loop / IF statement returning error

The code at the bottom is a simplified example of what we have. If I use the following: && echo "echo failed" $? returns 1 When I use if ; then echo "echo failed" ; fi $? returns 0 Does anyone know what's wrong with this? Using AIX 6.1 and KSH for NUM in 1 2 3 do ... (5 Replies)
Discussion started by: jfxdavies
5 Replies

3. Solaris

Error during running sqlplus command from shell script in Solaris

I am using following code to connect to oracle database from solaris shell script. which will try thrice to connect the database ...at the 4rth atempt it will exir=t. count=0 while ; do sqlplus -s $usrname/$password@dbSID <<-EOF | tee $logfile WHENEVER OSERROR EXIT 9; WHENEVER SQLERROR... (4 Replies)
Discussion started by: millan
4 Replies

4. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

5. Shell Programming and Scripting

[solved] Process ssh command in while loop

I have a script that reads a file containing a list of server names. It's suppose to loop through the list of names and execute a command on the remote server using ssh. It processes the ssh command for the first server in the list and then exits. Here's the code: #!/bin/bash ... (2 Replies)
Discussion started by: westmoreland
2 Replies

6. UNIX for Advanced & Expert Users

[Solved] Add hardware in virt-install command

Hi, Again a question about virt-install. Someone knows how to add hardware in the virt-install command? I put the first disk with --disks path=/.... but I need a second disk and I don't know how to include it? Thanks (2 Replies)
Discussion started by: hiddenshadow
2 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Syntax error for awk in a loop

can some one please tell me what is the problem with my syntax:confused: I have 100 files in one folder 1. want to read each of the line by line 2. calculate their number of the words between the first word and the last word of each line 3. create file for each file with number of words... (8 Replies)
Discussion started by: A-V
8 Replies

8. Shell Programming and Scripting

how to use sqlplus command inside for loop

I tried this: for region in 'raj' 'kt' 'kol' 'krl' 'chn' 'dl' 'hr' 'bih' 'ap' do sqlplus -s huw$region/`echo $region`huw#321@huw$region<<! set serveroutput on begin select count(*) from tcd_preferred_cust_201109 end; / exit; done but the error shows like: Syntax error at line 4 :... (1 Reply)
Discussion started by: deepakprasad29@
1 Replies

9. Shell Programming and Scripting

(solved) Shell scripting to access SQLPLUS using variable

I have shell script which will try to login to SQL Plus and retrieve some data, based on the outcome i will proceed further Below is the content of the file pebblz02% cat test1.ksh #! /bin/ksh dummyvar=`sqlplus -S csm_admin/csm_admin@SIDNAME <<EOF echo hi; exit; EOF` Error message on... (0 Replies)
Discussion started by: kiranlalka
0 Replies

10. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies
Login or Register to Ask a Question