LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 10:19 AM   #1
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 28

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, 11:17 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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, 12:22 PM   #3
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 28

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, 12:29 PM   #4
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 28

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 12:32 PM.
 
Old 04-03-2015, 01: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, 01:53 PM   #6
ampapa
LQ Newbie
 
Registered: Feb 2012
Posts: 28

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

ampapa,
 
Old 04-04-2015, 02:58 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
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, 03:56 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:24 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
Open Source Consulting | Domain Registration