cx_Oracle library in python import failure caused crontab program fails, and no error

We encountered a problem today:

       A python script is running normal command line, into the crontab will not work, nor the log records, looking for a long time, finally found the problem.

In the above script Finally, the procedure is as follows:

#!/usr/local/bin python  
# coding=utf8  
import cx_Oracle  
import sys  
import time  

Note that here

import cx_Oracle  

cx_Oracle need to rely on the oracle ORACLE_HOME environment. I found ORACLE_HOME is defined in the / etc / profile, modify the content here is work for all users, but for crontab does not work. The following is a scope of each file:

 

(1) / etc / profile: This file is set up for each user environment information system, when a user first logs in, the file is executed and collect shell settings from the configuration file /etc/profile.d directory. .
(2) / etc / bashrc: each user to perform a file operation when the bash shell bash shell is opened, the file is read.
(3) ~ / .bash_profile: Each user can use the file input information specific to shell their own use, when a user logs in, the file is performed only once by default, he set some environment variables, perform user!. bashrc file.
(4) ~ / .bashrc: This file contains dedicated to the bash shell bash your information, log on, and when every time you open a new shell when the the file is read.
(5) ~ / .bash_logout: each time when the system exits (exit bash shell), the file is executed Moreover, / etc / profile variables set (global) may be applied to any user, and ~ / .bashrc. variables (local), etc. can only be set in succession / etc / profile of the variables, they are "parent-child" relationship.

(6) ~ / .bash_profile interactive, login operation mode into the bash ~ / .bashrc interactive mode into the non-login bash often run both disposed substantially identical, so that the former will typically call the latter.

Solution:

30 7 * * *  . /etc/profile; /usr/local/bin/python2.7 /data/storeDataToOracleDB.py  &  

Here added

. /etc/profile;  

ok, problem solved.

Article from: https://www.cnblogs.com/chenjianhong/p/4144518.html

Published 35 original articles · won praise 61 · views 160 000 +

Guess you like

Origin blog.csdn.net/woailyoo0000/article/details/88837986