Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron job not assuming user profile? 1

Status
Not open for further replies.

MCubitt

Programmer
Mar 14, 2002
1,081
GB
I have added a cron job to user Oracle's cron:
Code:
22 13 * * * /home/oracle/km/Backup/_DB_Session_List.unix IFSD /home/oracle/km/sess.tmp

...which should list the sessions against an Oracle database.

But the result is a mail to Oracle:
From daemon Fri Feb 11 13:23:00 2005
Date: Fri, 11 Feb 2005 13:23:00 -0600
From: daemon
To: oracle

/home/oracle/km/Backup/_DB_Session_List.unix[18]: sqlplus: not found.

It’s as though sqlplus is not found, but surely running as Oracle’s cron, it assumes Oracle’s default profile?

The unix script is:
Code:
 #!/bin/sh

srcdb=$1
sessionfile=$2

# Get path of script
ScriptName=`basename $0`
CurrentDirectory=`pwd`
ScriptDirectory=`dirname $0`
case "${ScriptDirectory}" in /*) ;;
  .) ScriptDirectory="$CurrentDirectory" ;;
  *) ScriptDirectory="$CurrentDirectory"/"$ScriptDirectory" ;;
esac
scriptpath=$ScriptDirectory

ORACLE_SID=$srcdb; export ORACLE_SID
sqlplus -s 'sys/oracle as sysdba' @$scriptpath/_DB_Session_List.sql $sessionfile

exit



Applications Support
UK
 
No, cron jobs do NOT run the .profile
option 1) Edit the script to add
Code:
. ~oracle/.profile
at the top
Option 2) change the cron entry to
Code:
su - oracle -c /home/oracle/km/Backup/_DB_Session_List.unix IFSD /home/oracle/km/sess.tmp

Columb Healy
 
Columb,

Thank you for that, I had no idea at all!

Since the Unix script calls another and another, do each need that . ~ oracle... or only the first? (If using option1 )

thanks



Applications Support
UK
 
You should only need it in the first one. I'm assuming that all the Oracle environment variables are exported so that they'll appear in all called scripts.

Columb Healy
 
Having many problems with TekTips timing out so Ill try posting a reply for the 100th time!

I tried the crontab entry since it's all in one place that way and older scripts will now work (!)

Code:
30 15 * * * su - oracle -c /home/oracle/keymed/Backup/_DB_Session_List.unix IFSD /home/oracle/keymed/sess.tmp

but I get
From daemon Fri Feb 11 15:31:02 2005
Date: Fri, 11 Feb 2005 15:31:01 -0600
From: daemon
To: oracle

Cannot su to "oracle" : Authentication is denied.

Any ideas, please?





Applications Support
UK
 
..actually, I'll use the method in the script, Thanks!


Applications Support
UK
 
Just for completeness, su - oracle -c should be OK, but only if you're su'ing from root, otherwise a password will be required, hence the authentication error.
 
Ken, thanks. That makes sense.

Cheers


Applications Support
UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top