Link to home
Create AccountLog in
Oracle Database

Oracle Database

--

Questions

--

Followers

Top Experts

Avatar of mrt1
mrt1

SQLLoader / UNIX Script
Hi, I've been asked to create a UNIX script to run Oracle SQLLoader.
Has anyone got a good example of this?
I want to pass the file locations of the control file, log file AND data file to SQLLoader.
The UNIX script just needs to check that the relevant files exist, pass the information to SQLLoader
(via the command line) and then check that everything went OK (i.e check for a .bad file, etc.)
Any help would be appreciated.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of kp397kp397

HI mrt1
You can do following..

Create a shell script, in which store control,log and bad file locations in a host variables, say cfile,lfile and bfile respectively.By using UNIX shell syntax , check all files/path exist.If everything is fine then execute sqlloader as below...

sqlldr userid/passwd control=$cfile/ctl_file.ctl log=$lfile/logfile.log bad=$bfile/bad_file.bad

Include this in shell script.

good luck.

kp397

Avatar of waynezhuwaynezhu

Below is a short  and simple one.  [Assume $1->controlfile,$2->logfile, $3->badfile,
userid=scott/tiger, and the email address to be notified is abc@xyz]
-------------------------------------------------------------------------------------------

#!/bin/sh

if [ $# -ne 3 ]; then
echo "Usage: $0 controlfile logfile badfile"
exit
fi

sqlldr scott/tiger control=$1 log=$2 bad=$3 #[,keyword=value,...]

if [ `cat $3 | wc -l` -gt 0 ]; then
mailx -s "SQL*LOADER badfile" abc@xyz < $3
fi

You can use the command-line options:

sqlldr scott/tiger control=emp.ctl data=emp.dat

The data option is overwriting our "INFILE" section in the control-file !

To check your result, use i.e. "grep","sed","awk" from the commandline to check your log-file.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


ASKER CERTIFIED SOLUTION
Avatar of rahulakrahulak

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

You could also check for existence of bad file by

if [ `ls -ltr bad | wc -l` -ne 0 ]
 echo " bad file exists " >> call_loader.log
fi

Yuck....it shud have been  somethin like *.bad instead of bad.


Oracle Database

Oracle Database

--

Questions

--

Followers

Top Experts

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.