Monday, March 4, 2013

Python cx_Oracle not working in Cronjob

cx_Oracle error in Cronjob execution. I've found that
adding environment variables in the crontab works
like charm. Steps to check if the cx_Oracle work:
test_cx_oracle.py
try:
import cx_Oracle
print 'cx_Oracle works'
except:
print 'cx_Oracle error'
In your crontab add,
 * * * * * python /path/to/test_cx_oracle.py.
Notice that the cron will execute every minute.
You will received error notification in your email
$ tail /var/spool/mail/oracle

Edit your cron:

ORACLE_HOME = '/path/to/db_1'
LD_LIBRARY_PATH = '/path/to/db_1/lib:/lib:/usr/lib'

* * * * * python /path/to/test_cx_oracle.py

Save and exit, wait for cron to fire then check your
mail again. You should received 'cx_Oracle works'
notification. Hope it helps.

No comments: