Sent via Deja.com http://www.deja.com/
Before you buy.
In article <8qtl2j$hqo$1...@nnrp1.deja.com>,
I can't run my usual .profile, since it uses the interactive features of
oraenv to deal with multiple $ORACLE_SIDs. Presumably using oraenv with
ORAENV_ASK=NO is the part of my .profile that I need, but it just
doesn't work unless I su - oracle.
Oh, and I apologize for the atrocious formatting of the original
question. Somewhere between deja.com's preview and Netscape 6.2, it was
totally trashed.
> In article <8qtl2j$hqo$1...@nnrp1.deja.com>,
> Joseph T <jth...@my-deja.com> wrote:
> > Why is it that if I run a shell script containing oraenv from cron
> > as the
> > oracle user, it doesn't work; but if I have root run it in cron
> > with su - oracle -c script_name, it runs?
[edit]
--
Joseph Thvedt
jth...@my-deja.com
cron does not invoke any shell startup features, such
as .profile, .bash_profile. .login, .cshrc, etc., so all the cron job
has as far as environment is the default /etc/profile settings. Since
you are running an interactive .profile you will want to create a
version of that, possibly named .cron_profile, that you can invoke from
cron jobs without the interactive components. Yes, this will
necessitate multiple .cron_profile files (to deal with the multiple
SID's) or you'll need to make the .cron_profile as universal as
possible and set the ORACLE_SID value in each cron job.
When you run as root and invoke "su - oracle -c ..." you set the
environment for oracle without the interactive commands; the "su -
oracle" does this. Unfortunately cron does not work in this manner and
you must set the environment in the scripts.
--
David Fitzjarrell
Oracle Certified DBA
[edit]
> > > > Why is it that if I run a shell script containing oraenv from cron
> > > > as the
> > > > oracle user, it doesn't work; but if I have root run it in cron
> > > > with su - oracle -c script_name, it runs?
> >
[edit]
> cron does not invoke any shell startup features, such
> as .profile, .bash_profile. .login, .cshrc, etc., so all the cron job
> has as far as environment is the default /etc/profile settings. Since
> you are running an interactive .profile you will want to create a
> version of that, possibly named .cron_profile, that you can invoke from
> cron jobs without the interactive components. Yes, this will
> necessitate multiple .cron_profile files (to deal with the multiple
> SID's) or you'll need to make the .cron_profile as universal as
> possible and set the ORACLE_SID value in each cron job.
>
> When you run as root and invoke "su - oracle -c ..." you set the
> environment for oracle without the interactive commands; the "su -
> oracle" does this. Unfortunately cron does not work in this manner and
> you must set the environment in the scripts.
Not to beat a dead horse, but isn't oraenv supposed to do that very
thing? It sets $PATH; it sets $ORACLE_SID; it sets $ORACLE_HOME. Or at
least it does when not run from cron. What is there about a generic,
no-.profile, cron environment that prevents oraenv from doing its job?
>
> --
> David Fitzjarrell
> Oracle Certified DBA
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
As I said before, cron does NOT set environment, including modified
PATH's. Since the PATH set when 'oracle' runs cron jobs is the default
PATH from /etc/profile local settings are not available, and one of
those local settings is a modified path to point to various and sundry
directories not included with the default PATH. The cron jobs run
under the 'oracle' id cannot find the oraenv script so it can't do its
job. Try explicitly pathing the oraenv line in your cron scripts
so 'oracle' can run them. Also, as I said previously, the "su -
oracle -c" sets the environment as though 'oracle' had actually logged
into the system; cron does not. This is why the scripts, run
by 'root', can find the oraenv script and the cron jobs run by 'oracle'
cannot.
# are we an interactive shell?
if [ "$PS1" ]; then
echo "The SIDs on this machine are:"
cat /var/opt/oracle/oratab | awk -F: '{print $1}' | grep -v "#"
ORAENV_ASK=YES
export ORAENV_ASK
. oraenv
fi
I believe something like this will solve your problem! My scripts run
from crontab under Oracle with no problems. I also have a config file
that lists all the SIDs I wish to run scripts for, then inside my shell
scripts I loop through the entries in that file. This is cool way to
run scripts for multiple instances without having to hardcode anything
in your scripts.
HTH
> In article <8qu11j$s29$1...@nnrp1.deja.com>,
> kal...@my-deja.com wrote:
> > All the scripts I run are from Oracle's cron file. Each shell script
> > that runs explicitly sources Oracle's .bash_profile. Your config file
> > may be different depending on which shell you are using.
> >
>
> I can't run my usual .profile, since it uses the interactive features of
> oraenv to deal with multiple $ORACLE_SIDs. Presumably using oraenv with
> ORAENV_ASK=NO is the part of my .profile that I need, but it just
> doesn't work unless I su - oracle.
>
> Oh, and I apologize for the atrocious formatting of the original
> question. Somewhere between deja.com's preview and Netscape 6.2, it was
> totally trashed.
>
> > In article <8qtl2j$hqo$1...@nnrp1.deja.com>,
> > Joseph T <jth...@my-deja.com> wrote:
> > > Why is it that if I run a shell script containing oraenv from cron
> > > as the
> > > oracle user, it doesn't work; but if I have root run it in cron
> > > with su - oracle -c script_name, it runs?
> [edit]
The .profile thing is no problem. All you have to do is re-write it a bit to
only run certain things (i.e. shell variable initialization, etc.) when it
is not an interactive shell. When you run from cron you get a
non-interactive shell. To determine if you are in an interactive shell or
not, parse the contents of $- as it will contain the character "i" (amongst
others) in an interactive shell.
in my .profile, I made oraenv conditional:
case $- in
*i*) SIDLIST=`awk -F: '/^[^#]/{printf "%s ",$1} ' /etc/oratab`
echo "SIDs on this machine are $SIDLIST"
ORAENV_ASK=
. /usr/lbin/oraenv
;;
esac
Now I source my .profile in the script. Since it isn't interactive, it
skips oraenv. I call that in my script, just as I've been doing all along:
. /my_home_path/.profile
ORAENV_ASK=NO
ORACLE_SID=X
. /usr/lbin/oraenv
yada, yada, yada...
Bob's your uncle!
I'm still not clear as to why just calling /usr/lbin/oraenv in the
script doesn't work. And before "oratune" pipes in again (imagine me
typing v e r y s l o w l y)-- I KNOW that .profile sets env vars & the
path that I need. However, as it relates to Oracle, I believe oraenv
ALONE sets those things.
In article <8r0g3e$ro6$1...@nnrp1.deja.com>,
kal...@my-deja.com wrote:
> I also have multiple SIDs on one machine. I think what you need in
> your .profile is a check to see if the shell is interactive or not.
> in your scripts.
[edit]
> HTH
--
Joseph Thvedt
jth...@my-deja.com
If it did you wouldn't need to invoke your .profile, would you? The
oraenv script relies upon the current environment and since there is
none cannot function properly. (I typed THAT V E R Y S L O W L Y so
you might grasp the concept.)
> In article <8r0g3e$ro6$1...@nnrp1.deja.com>,
> kal...@my-deja.com wrote:
> > I also have multiple SIDs on one machine. I think what you need in
> > your .profile is a check to see if the shell is interactive or not.
> > in your scripts.
>
> [edit]
>
> > HTH
>
> --
> Joseph Thvedt
> jth...@my-deja.com
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
David Fitzjarrell
Oracle Certified DBA
Not that it matters that much, since my problem is solved; I'm just
curious.
In article <8r31dg$iso$1...@nnrp1.deja.com>,
ora...@aol.com wrote:
[edit]
> If it did you wouldn't need to invoke your .profile, would you? The
> oraenv script relies upon the current environment and since there is
> none cannot function properly. (I typed THAT V E R Y S L O W L Y so
> you might grasp the concept.)
>
Don't you define $ORACLE_HOME before oraenv in the .profile ?
If not then I'm confused too.
Nope. oraenv sets $ORACLE_HOME based on $ORACLE_SID. This allows for
multiple ORACLE_HOMEs -- for example, I have both 8.0.5 & 8.1.6 installed.
It was a slight exaggeration to say there isn't _anything_ before
oraenv. I do set $ORAENV_ASK & $ORACLE_SID, which are required by oraenv
if it's to be non-interactive. And yes, there's _something_ else in
.profile that's required, as "oratune" and others pointed out. I just
don't know what it is.
>
> If not then I'm confused too.
>
[edit]