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 > cron running sql script

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-28-03, 07:18
kondaoracle kondaoracle is offline
Registered User
 
Join Date: Sep 2003
Posts: 33
cron running sql script

Hi All,

I am running the script on Oracle8i under AIX.

I have a pl/sql script(procedure) which should run for every week ie on monday. I need to put this script file(procSample.sql located at /usr/myProc directory for ex.) in a cron job. I dont want to go for dbms_jobs utility provided by oracle. My req is to put it in cron.

Can any one suggest me in doing this one in detail.
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 01-04-04, 13:20
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi,
I dont know how to use crontab exactly on AIX. But I think it is realy the same as SCO Unix.

unload your crontab by using "crontab -l > mycron"
Now edit the file mycron and append following row.
30 1 * * 1 /usr/myProc/procSample.sql
It means : execute the procSample.sql every Monday at 1:30 .

Now save the file and load the crontab with the command
"crontab mycron" on Unix Shell.

Check the effect by typing "crontab -l" again.

Remember that there is no empty row at the end of your mycron file.
Otherwise an error occur.

More help you will get by typing "man crontab" on your AIX-Unix Shell.
__________________
Greetings from germany
Peter F.

Last edited by fla5do; 01-04-04 at 13:37.
Reply With Quote
  #3 (permalink)  
Old 01-05-04, 10:43
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 3,102
Quote:
Originally posted by fla5do
Hi,
I dont know how to use crontab exactly on AIX. But I think it is realy the same as SCO Unix.

unload your crontab by using "crontab -l > mycron"
Now edit the file mycron and append following row.
30 1 * * 1 /usr/myProc/procSample.sql
It means : execute the procSample.sql every Monday at 1:30 .
...only it won't work since you can't ask shell to execute an sql script. You'll need to invoke sqlplus to run the script.

1) type "crontab -e" to edit cron table: this will launch your visual editor (I guess default would be vi)
2) create an entry in it similar to this:
30 1 * * 1 . /home/yourloginid/.profile;sqlplus @/usr/myProc/procSample.sql
3) save the cron table
4) enjoy.

Please note that you have to execute your profile explicitly before attempting to run sqlplus (assuming your profile contains all necessary Oracle environment variables).
__________________
===
Nick Ivanov
Freelance database consultant
www.datori.org
Reply With Quote
  #4 (permalink)  
Old 01-05-04, 19:23
kondaoracle kondaoracle is offline
Registered User
 
Join Date: Sep 2003
Posts: 33
Hi n_i,

Thanks for your reply but i have one doubt over here.

You gave the following script:

30 1 * * 1 . /home/yourloginid/.profile;sqlplus @/usr/myProc/procSample.sql


Is it not necessary to mention UserId, Password and Connection String to connect to oracle in the above line?
How it will be connected?
Reply With Quote
  #5 (permalink)  
Old 01-06-04, 10:10
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 3,102
Quote:
Originally posted by kondaoracle


30 1 * * 1 . /home/yourloginid/.profile;sqlplus @/usr/myProc/procSample.sql


Is it not necessary to mention UserId, Password and Connection String to connect to oracle in the above line?
How it will be connected?
Well, yes. Obviously you need to connect. You could either specify it on the command line or use "/nolog" option and connect from your script...
__________________
===
Nick Ivanov
Freelance database consultant
www.datori.org
Reply With Quote
  #6 (permalink)  
Old 01-06-04, 19:54
kondaoracle kondaoracle is offline
Registered User
 
Join Date: Sep 2003
Posts: 33
Hi n_i

can u pls make it more clear...

in my pl/sql i sud write /nolog ? thats what u r mentioning or
see the following

30 1 * * 1 . /home/yourloginid/.profile;sqlplus /nolog @/usr/myProc/procSample.sql


i didnt get you properly
Reply With Quote
  #7 (permalink)  
Old 01-07-04, 13:45
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 3,102
Quote:
Originally posted by kondaoracle
Hi n_i

can u pls make it more clear...

in my pl/sql i sud write /nolog ? thats what u r mentioning or
see the following

30 1 * * 1 . /home/yourloginid/.profile;sqlplus /nolog @/usr/myProc/procSample.sql


You can connect to a database by two methods, as you probably know:

1) specify userid, password, and service name on the sqlplus command line:

sqlplus userid/pass@svcname @script.sql

2) specify /nolog on the sqlplus command line, like this:
sqlplus /nolog @script.sql

and then use CONNECT command within the script

See SQLplus reference manual for more details
Reply With Quote
Reply

Thread Tools
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