Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 17:23
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 136
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, 17:33
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 2,227
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 .
__________________
===
Nick Ivanov
Freelance database consultant
www.datori.org
Reply With Quote
  #3 (permalink)  
Old 12-14-07, 18:38
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 136
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, 18: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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On