If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help to expalin cron problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-04, 10:06
telemorgan telemorgan is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Help to expalin cron problem

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
Reply With Quote
  #2 (permalink)  
Old 10-19-04, 14:21
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
When the cron daemon runs anything it doesn't set up the shell environment the way interactive shell does. This means in particular that /home/oracle/.profile does not get executed and as a result whatever environment variables should be set for Oracle utilities, aren't.

You'll need to explicitly run the oracle user profile before doing anything else in your script, for example
Code:
#!...
test -z "$ORACLE_HOME" && . /home/oracle/.profile
# the rest of the script

Last edited by n_i; 10-19-04 at 16:46.
Reply With Quote
  #3 (permalink)  
Old 10-19-04, 16:47
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
..............
Reply With Quote
  #4 (permalink)  
Old 10-20-04, 09:37
telemorgan telemorgan is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Thank you very much.

This worked like a charm. Once I invoked the oracle profile the script ran fine.
Reply With Quote
  #5 (permalink)  
Old 10-20-04, 09:45
telemorgan telemorgan is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
one question however, what is the ^ in the "^OK " doing?
Reply With Quote
  #6 (permalink)  
Old 10-20-04, 12:09
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Quote:
Originally Posted by telemorgan
one question however, what is the ^ in the "^OK " doing?
grep -c '^OK'
number of lines beginning with string 'OK'
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On