tags:

views:

175

answers:

2

I'd like to run a sqlplus script from a cron job.

I thought I could put a line like:

CONNECT "myuser/mypass@mydb"

within the script and then just execute it with:

sqlplus @myscript

However, when I do so, I get:

SP2-0306: Invalid Option
SP3-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

Am I misunderstanding the usage of the connect command?

A: 

When running CONNECT inside SQL*Plus, remove the quotes:

CONNECT myuser/mypass@mydb

They double quotes are required if you are passing the credentials as an argument to sqlplus:

sqlplus "myuser/mypass@mydb"

, for the shell to parse myuser/mypass@mydb as a single argument if you have spaces in your connection identifier or use additional options like AS SYSDBA.

Quassnoi
Tried that. No effect.
Wade Williams
@Wade: Does it connect from a command line with the same credentials?
Quassnoi
Yes. sqlplus myuser/mypass@mydb works fine.
Wade Williams
@Wade: does you script fail only when run under `cron`? Could you please put `CONNECT myuser/mypass@mydb` into a `file.sql` and run `sqlplus /nolog @file.sql`?
Quassnoi
I'm not running it under cron yet. What you describe is what I was doing. However, the key difference is that I wasn't using the /nolog option. With that option, it works. Thanks for the help.
Wade Williams
A: 

Use the /NOLOG option.

sqlplus /nolog @myscript
Jeffrey Kemp
oh, I see you've already got that... :)
Jeffrey Kemp