LinuxQuestions.org
Review your favorite Linux distribution.
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 04-03-2015, 11:19 AM   #1
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 25

Rep: Reputation: Disabled
Problem w/.bash script... need help


I'm trying to loop through a query in SQLDeveloper by passing the query a different Period and I'm having a problem getting the syntax correct.

Individually the following works correctly on its own:

Code:
#!/bin/bash
 for i in `seq -f "%02g" 1 5`;
    do
    echo $i
 done
$ ./test.sh
1
2
3
4
5


the following also executes correctly:

Quote:
sqlplus table1/$userpass@Mytable <<EOF
@./sqlcode.sql $i
EOF
but when I try to wrap the loop around my sqlplus command

Code:
#! /bin/sh
userpass=read
for i in `seq -f "%01g" 1 3`;
  do
        sqlplus -S  table1/$userpass@Mytable <<EOF
        @./sqlcode.sql $i
        EOF
done
I get the following error:

./test.sh: line 13: syntax error: unexpected end of file

Does anyone have any ideas on what's going on?
 
Old 04-03-2015, 12:17 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Not sue I get the idea of the for loop? If you are simply using 1 - 3 the 01g does not appear to do anything for you.

userpass being set to the string read, was this your intention or were you hoping to ask the user for the password with the read command?

As for the sqlplus line, not sure I see the point of a here document for a single line. Also, the ./ is not required if the file is in the current directory.

Lastly, there are not 13 lines of code in your shell script so the error message would imply you are not showing the entire script.

For debugging the issue you could try placing set -xv as second line in script and see where your error is coming from.
 
Old 04-03-2015, 01:22 PM   #3
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks for the follow up.

The loop is for Periods 1-12, I simply want to run the same script 12 times for different periods of the month. The periods were originally formatted in 01,02, etc.

The password 'userpass' was just an easier place to enter the credentials from our TEST and PROD environments, I could have placed on the sqlplus line as easy.

Since the sql generates a large file, 10gig I didn't want to look at the spooling of data on the terminal and the only way to stop the output was passing in the file sqlcode.sql

Code:
!/bin/sh
set -xv
userpass=read
export ORACLE_HOME=/u01/app/oracle/product/11.2.0
export PATH=$PATH:$ORACLE_HOME/bin


for i in `seq 1 12`;
  do
    sqlplus table1/$userpass@Mytable <<EOF
    @sqlcode.sql $i
    EOF 
 done
same error... sorry I originally pulled out the path info in the script... there are 13 lines of code.

/test.sh: line 14: syntax error: unexpected end of file
 
Old 04-03-2015, 01:29 PM   #4
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
I found the error, it was related to extra garbage on the script, must have come from copying from notepad++...

Is there an efficient way for copying to a bash script from notepad++ to avoid the problem I was having?

ampapa,

Last edited by ampapa; 04-03-2015 at 01:32 PM.
 
Old 04-03-2015, 02:05 PM   #5
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Is there an efficient way for copying to a bash script from notepad++ to avoid the problem I was having?
You should try dos2unix command.
 
Old 04-03-2015, 02:53 PM   #6
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks, will do next time.

ampapa,
 
Old 04-04-2015, 03:58 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
notepad++ has the option to save as a nix file so you should be able to save it without problem.

i would also note that your here document won't work either as the ending is not at the start of the line and you did not preceed the start with a hyphen.
 
Old 04-04-2015, 04:56 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
If I remember well the second, closing EOF (inside the for loop) must begin at the beginning of the line (there should be no space before)
 
  


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
[SOLVED] Problem in exporting variable from bash script to expect script uk.engr Linux - Newbie 3 06-14-2012 02:57 AM
Problem running an Expect script within a Bash script mbeipi Programming 8 03-15-2011 05:07 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 06:39 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 11:53 AM


All times are GMT -5. The time now is 12:53 PM.

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