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!

crontab and tnsping

Status
Not open for further replies.

Teckh

Programmer
Aug 3, 2005
6
CA
Hi,

I am trying to create a script that does a tnsping on an oracle DB every 5 minutes by a crontab.

I know my problem relates to the crontab not being able to convert the Oracle service name.

In the crontab I have:
5,10,15,20,25,30,35,40,45,50,55,0 * * * * /library/file_transfer/scripts/OraclePing.sh

and the script looks like:

echo `date '+%m/%d/%y %H:%M:%S'` - `/appl/oracle/iofm/iofmora9i/8.0.6/bin/tnsping or123 | tail -c 93` >> /library/file_transfer/OraclePing.txt

The part that specifically fails is 'tnsping or123' as it is unable to resolve the or123 service name.

Does anyone know how I can get around this problem?

Thanks.
 
I've run a few more tests and I have found a way around the tnsname I believe. However, there is still a problem as tnsping still fails. The script runs fine outside of crontab so I assume its an environment problem?

08/03/05 19:15:00 - TNS Ping Utility for IBM/AIX RISC System/6000: Version 8.0.6.3.0 - Production on 03-AUG-2005 19
:15:00 (c) Copyright 1997 Oracle Corporation. All rights reserved. Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HO
ST=<removed>)(PORT=<removed>)) Message 3509 not found; No message file for product=NETWORK, facility=TNS


 
Make sure the $PATH variable as used from the command line is included early within your script. Also, explicitly set $ORACLE_HOME and $ORACLE_SID within it.
 
or run a cron wrapper script from root's crontab

In root's crontab put:
5,10,15,20,25,30,35,40,45,50,55,0 * * * * /library/file_transfer/scripts/OraclePing.crn

OraclePing.crn (mode at least -r-x------, owner root):

su - oracle <<eof_su
/library/file_transfer/scripts/OraclePing.sh
eof_su

I assumed "oracle" is your oracle user. By su -ing to oracle you set up the complete oracle environment (must be "su - oracle" not "su oracle").


HTH,

p5wizard
 
When using su, at least on the command line, it asks for the users password. How does the crontab handle that input request?
 
How does the crontab handle that input request
No password asked if run as root.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi,

I tried using the cron wrapper.

I setup a file with the following in it:
su - oracle <<eof_su
/library/file_transfer/scripts/OraclePing.sh
eof_su

and used the following in the crontab

5,10,15,20,25,30,35,40,45,50,55,0 * * * * /library/file_transfer/scripts/OraclePing.crn

now the script does not fire at all, no output file is created.
 
And what about this root's crontab entry ?
5,10,15,20,25,30,35,40,45,50,55,0 * * * * su - oracle -c '/library/file_transfer/scripts/OraclePing.sh'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
i'm not sure but i think this works every 5 minutes:-

Code:
*/5 *   *   *   *


Kind Regards
Duncan
 
I do not have root access to the system. Is there any other way to set up a crontab to run a tnsping?

Thanks.
 
duncdude, yes, that would run every 5 minutes, but that syntax is only supported on certain versions of the cron daemon, such as vixie-cron on Linux.

Annihilannic.
 
If you don't have root access, then you can't use root's crontab and can't use an 'su - oracle' wrapper.

You can still create a wrapper script that sets a full oracle environment:

In oracle's crontab put:
5,10,15,20,25,30,35,40,45,50,55,0 * * * * /library/file_transfer/scripts/OraclePing.crn

OraclePing.crn (mode at least -r-x------, owner oracle):

#!/bin/ksh
# # #
# build complete oracle env for cron-started process
. /etc/profile
. ${HOME}/.profile
# # #
# Now run the OraclePing script
/library/file_transfer/scripts/OraclePing.sh

Again assuming that user "oracle" owns your Oracle installation. I also assumed korn shell as login shell.

Or easier:

Just put the two dot commands to build the environment in the beginning of your OraclePing.sh script...


HTH,

p5wizard
 
Thanks p5wizard.
I just needed to set the oracle env in the script like you suggested.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top