Sponsored Content
Top Forums Shell Programming and Scripting Calling SQL LDR and SQL plus scripts in a shell script Post 302143943 by rajagavini on Monday 5th of November 2007 01:05:23 PM
Old 11-05-2007
Calling SQL LDR and SQL plus scripts in a shell script

Hi-
I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment...

I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert statement to parse through the records in Table1 and load the necessary results into a Table. (Table2). This works fine too.

Here is how my script looks like...

# Always truncate table 1 before loading data.
print "truncate table table1;" | sqlplus -s userid/password@db>$now.log
sqlldr userid/password@db control=dbload.ctl>>$now.log
# Always truncate table 2 before loading data.
print "truncate table table2;" | sqlplus -s userid/password@db>>$now.log
# Parse through Table1 and load only necessary records to Table2.
print "insert into table2 select id, min(STARTDATE) as startdate from table1 group by id, to_char(STARTDATE,'mm/dd/yyyy');" | sqlplus -s userid/password@db>>$now.log

I call this script myscript.sh, which will be run via crontab every 15 mins.

Here are my questions:
1) Note how I establish a database connection to execute every sql I need to run? I am thinking there should be an easy way to this. I looked into the "here documents" but not sure how I can use them above. Do I really need to use the "here document" or is my script good the way as it is now?
Would it open and close the db connections for each sql correctly?

If I do use the "here document", do I need to have one for the sqlldr and the other for all the sqlplus part?

Please advise best way to go ahead.
Thanks
RG
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling SQL scripts through Shell Script

Oracle and Scripting gurus, I need some help with this script... I am trying to add the query SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'METADATA' in the current script.... Read the result set and look for the TABLE_NAME field. If the field is pointing to one table eg.... (18 Replies)
Discussion started by: madhunk
18 Replies

2. UNIX for Advanced & Expert Users

Calling PL/SQL Script in Shell Programming

Hi all, In a shell script I need to pass two parameters to a pl/sql script and get the ouput of the pl/sql script and use it in shell script. For example Shell script : test.sh PL/SQL script : get_id.sql parameter1 parameter2 Actually get_id.sql has a select statement something... (1 Reply)
Discussion started by: lijju.mathew
1 Replies

3. Shell Programming and Scripting

calling sql file from shell script

Hello everybody I need help calling sql file from shell script. Can anyone help me creating a small shell script which calls an sql file . The .sql file should contain some select statements like select emp_no from emp_table; select emp_id from emp_table; And the results should be... (6 Replies)
Discussion started by: dummy_needhelp
6 Replies

4. Shell Programming and Scripting

any possible solution on sql calling scripts

hi all, i have a function which will take i/p as a ddl sctipt as i/p and execute it, let function execute_sql { db_var="$1" v_cnt=`sqlplus -s XXXXX/XXXXX@aXXX << ENDSQL | sed -e "s/Connected\.//" -e "/^$/d" set pagesize 0 feedback off verify off heading off echo off serveroutput on size... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

5. Shell Programming and Scripting

Calling sql in shell script with parameters

Dear All, I want to call an sql script within a unix shell script. I want to pass a parameter into the shell script which should be used as a parameter in teh sql script. e.g $ ./shell1.sh 5000129 here 5000129 is a prameter inside shell script i am calling one sql script e.g. ... (2 Replies)
Discussion started by: Radhe
2 Replies

6. UNIX for Advanced & Expert Users

Calling sql file from shell script

Hi I have a shell script that call a sql file. The sql file will create a spool file. My requirement is, when ever i get an OS error like file not found. I have to log it in a log file. Could some who worked in a like scenario help me by giving the code sample. Many Thanks.. (1 Reply)
Discussion started by: chintapalli001
1 Replies

7. Shell Programming and Scripting

calling a sql file in my shell script

Hi, I want to call a sql file in my shell script. see the below code:- if ] then ( isql -U${S_USER} -S${S_SERV} -w100 -b -h0 <<ENDSQL | sed -e "s/Password://" ${S_PWD} set nocount on go use ${S_DB} go // need to call a file name... (16 Replies)
Discussion started by: dazdseg
16 Replies

8. Shell Programming and Scripting

Calling sql file from shell script with parameters.

Hi, I am calling a sql file script.sql from shell script and passing few parameters also as shown below: sqlplus -S id/password @script.sql $param1 $param2 Now,In sql file I have to create a extract text file after querying oracle tables based on the parameters passed(param1,param2) as... (7 Replies)
Discussion started by: anil029
7 Replies

9. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

10. Shell Programming and Scripting

[Solved] Calling PL/SQL Block into Shell Script

Hi, i have one simple PL/SQL Block and i have saved it as .sql file, which i am trying to call from UNIX script. PL/SQL block structure CONNECT DB_NAME/PWD@Database whenever SQLERROR EXIT 1; Declare ..Variables... BEGIN --Code-- exception END; exit; I have save this block as... (3 Replies)
Discussion started by: abhii
3 Replies
make_combined_log.pl(1) 				      General Commands Manual					   make_combined_log.pl(1)

NAME
make_combined_log.pl - make combined logfile from SQL database SYNOPSIS
make_combined_log.pl <days> <virtual host> DESCRIPTION
This perl script extracts the httpd access data from a MySQL database and formats it properly for parsing by 3rd-party log analysis tools. The script is intended to be run out by cron. Its commandline arguments tell it how many days' worth of access records to extract, and which virtual_host you are interested in (because many people log several virthosts to one MySQL db.) This permits you to run it daily, weekly, every 9 days -- whatever you decide. NOTE
By "days" I mean "chunks of 24 hours prior to the moment this script is run." So if you run it at 4:34 p.m. on the 12th, it will go back through 4:34 p.m. on the 11th. KNOWN ISSUES
Because GET and POST are not discriminated in the MySQL log, we'll just assume that all requests are GETs. This should have negligible effect on any analysis software. This could be remedied IF you stored the full HTTP request in your database instead of just the URI, but that's going to cost you a LOT of space really quickly... Because this is somewhat of a quick hack it doesn't do the most robust error checking in the world. Run it by hand to confirm your usage before putting it in crontab. AUTHOR
Edward Rudd <eddie@omegaware.com> MAN PAGE CREATED BY
Michael A. Toth <lirul.lists@gmail.com> - based on comments of script COMMENTS
This man page was written using xml2man (1) by the same author. Manuals User make_combined_log.pl(1)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy