Results 1 to 2 of 2
Hello members,
I'm working on the Solaris environment and the DB i'm using is Oracle 10g.
Skeleton of what I'm attempting;
Write a ksh script to perform the following. I ...
- 10-07-2009 #1Just Joined!
- Join Date
- Oct 2009
- Posts
- 2
Looping through a shell script with sql statements
Hello members,
I'm working on the Solaris environment and the DB i'm using is Oracle 10g.
Skeleton of what I'm attempting;
Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a jist of what I'm attempting, below.
1. Copy file to be processed (one file at a time, from a list of 10 files in the folder ).
2 . Create a snapshot(n) table : Initialize n = 1Code:for i in * do cp $i /home/temp
-- creates my snapshot table and inserts records in SQLCode:create table test insert account_no, balance from records_all;
3. Checking if the table has been created successfully:
-- query out the number of records in the table -- always fixed, say at 400000Code:select count(*) from snapshot1
4. If table creation is successful,Code:if( select count(*) from snapshot(n) = 400000 ) echo " table creation successful.. proceed to the next step " else echo " problem creating table, exiting the script .. "
-- printing the max value to consoleCode:echo " select max(value) from results_all "
5. Process my files using the following jobs:
( m - initial value 001 )Code:./runscript.ksh - READ -i $m
( m - initial value 001 -- same as READ process_id )Code:./runscript.ksh - WRITE -i $m
-- increment m by 1
6. Wait for success log
7. looping to step1 to :Code:tail -f log($m)* | -egrep "^SUCCESS"
Copy file 2 to temp folder;
create snapshot(n+1) table
Exit when all the files have been copied for processing.
-- End of Step 1Code:done
Pointers on getting me moving will be very valuable.
thanks,
Kristina
- 10-08-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
First of all, you can do this (the SQL commands) in an SQL script (sqlplus), not a system shell script (bash, csh, ksh, etc). I would suggest that you first review the documentation for sqlplus.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote