If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > running all sql files from a unix directory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-14-07, 16:23
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
running all sql files from a unix directory

I am on solaris 5.8 and work on a 10.2.0.3 oracle database.
In my shell scripts, I have

#!/bin/ksh
sqlplus -s /NOLOG <<!EOF
connect user/pwd@database
@/data/dev/file1.sql
exit
!EOF
exit 0

The above code is good for executing a single file. Suppose, I want to run all the .sql files in the /data/dev directory, can I get an idea as to what needs to change in the above code ? There may be 100 of them...hence something like

@/data/dev/file1.sql
@/data/dev/file2.sql
.
.
.
@/data/dev/file100.sql
Reply With Quote
  #2 (permalink)  
Old 12-14-07, 16:33
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
One of the approximately 150 ways of doing it would be to
1) change your script to take the SQL file name as a parameter and
2) use the find command to run the new script: find . -name "*.sql" -exec yourscript.sh '{}' \;

Keep in mind that the order of their execution will be random, generally speaking .
Reply With Quote
  #3 (permalink)  
Old 12-14-07, 17:38
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
Thank you...I am getting real close (but not there yet)

I have all these file names in a file now...
ls *.sql >> sqllist

My sqllist now looks like :
file1.sql
file2.sql
.
.
.
file100.sql

How can I append a character @ in the first column on all lines in this file... If I get that, then I can run the
@sqllist
in my shell script.
I am looking for something besides the vi editor to get this automated.
Reply With Quote
  #4 (permalink)  
Old 12-15-07, 17:02
radoulov radoulov is offline
Registered User
 
Join Date: May 2007
Location: Milano, Italy
Posts: 22
Code:
printf "@%s\n" *.sql>all_together.sql
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On