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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help to explain this 3

Status
Not open for further replies.
Oct 9, 2003
174
US
Hey everyone

Could you guys help me to understand what is going on here. I have this simple script(script A). When I run it from the command prompt of the "oracle" user account,it is successful (output A). But when I setup the job to run under the same oracle user's cron it fails (output B). Please help me to explain what is going here and how I can fix it.

SCRIPT A:

#!/bin/ksh -x
#
# SET GLOBAL VARIABLES
DB="deltekcp griffon epay deltektc"
#
for x in $DB; do
if [ `/u01/app/oracle/product/8.1.7/bin/tnsping $x | grep -c "^OK "` -ne 0 ]; then
echo "$x : up"
else
echo "$x : down"
fi
done

OUTPUT A:

+ DB=deltekcp griffon epay deltektc testcp
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping deltekcp
+ [ 1 -ne 0 ]
+ echo deltekcp : up
deltekcp : up
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping griffon
+ [ 1 -ne 0 ]
+ echo griffon : up
griffon : up
+ /u01/app/oracle/product/8.1.7/bin/tnsping epay
+ grep -c ^OK
+ [ 1 -ne 0 ]
+ echo epay : up
epay : up
+ /u01/app/oracle/product/8.1.7/bin/tnsping deltektc
+ grep -c ^OK
+ [ 1 -ne 0 ]
+ echo deltektc : up
deltektc : up


OUTPUT B:

+ DB=deltekcp griffon epay deltektc testcp
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping deltekcp
+ [ 0 -ne 0 ]
+ echo deltekcp : down
deltekcp : down
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping griffon
+ [ 0 -ne 0 ]
+ echo griffon : down
griffon : down
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping epay
+ [ 0 -ne 0 ]
+ echo epay : down
epay : down
+ grep -c ^OK
+ /u01/app/oracle/product/8.1.7/bin/tnsping deltektc
+ [ 0 -ne 0 ]
+ echo deltektc : down
deltektc : down




Thanks
 
change your cron to su - oracle -c <SCRIPT>

su is very valuable for cron processing, as it executes with the evironment, and variable set up.
 
I tried that but got an error did I do this correct.

Cron entry

51 * * * * su - oracle -c /morgan/scripts/tt2 > /morgan/working/output.txt 2>&1


OUTPUT.TXT
su: Sorry
 
the same oracle user's cron
No su needed, but perhaps either sourcing the .profile or implementing some environment variables.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That is what is confusing me. Lets go back to my original post. I log into my box as the oracle user and run the script with no problem (output A). Under that same oracle user if I add the job to its cron and have it run. That is where I am having the problem (output B).

So I would think adding the `su - oracle` to the oracle's cron is just redundant. But I don't claim to be an expert at this stuff....

suggestions?
 
Output A is the result of running the script manaully just logged in as the oracle user.

Output B is the result of running the script via the oracle user's cron.

 
I insist on the environment issue (classical issue with cron jobs ...)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
More like some sort of timing issue in the ping script, is it possible to look at tnsping or is it a program?

Sorry did not notice that you created the cron at the oracle prompt, su is not needed, although it will just spawn another instance of the shell, and should work.

 
Hi telemorgan,

I am convinced (like PHV) that you are experiencing an "environmental issue". See the various recent post in this an other UNIX forums about cron and cron jobs. The man page for crontab (Solaris & Tru64) does say that the .profile is not executed.
To test this theory put the following line
/u01/app/oracle/product/8.1.7/bin/tnsping $x
before the if in the for loop and check the output. Run it for both scenarios.

Also, if you are using the su - oracle -c <SCRIPT> construct as suggested by cdlvj, I would recommend using quotes (") around the <SCRIPT>, eg: su - oracle -c "<SCRIPT>"
So your crontab entry would look like:
51 * * * * su - oracle -c "/morgan/scripts/tt2 > /morgan/working/output.txt 2>&1"


I hope that helps.

Mike
 
Put double quotes around the command

01 01 * * * su - oracle -c "command"

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant.
 
Could it be a dns issue, or location of the tnsname.ora, or parms in the file. Is it an ip address or dns name?
 
Just for test purpose, when logged as oracle user execute this command:
env > /morgan/scripts/myenv
Then amend your cron entry like this:
51 * * * * set -a && . /morgan/scripts/myenv && /morgan/scripts/tt2 > /morgan/working/output.txt 2>&1


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Alright guys, you were right (not that I doubted ya). it was an environment issue. I put the entry below in the begining of the script to source the oracle environment before executing and it worked.

#!...
test -z "$ORACLE_HOME" && . /export/home/oracle/.profile
# the rest of the script

I would like to thank you guys for your help. Couldn't have done it without a little assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top