在执行python3时定时任务用bash来嵌套有时候不行,所以可以在定时任务中可以使用
source /etc/profile && 命令 实现,可行
crontab执行python脚本报错:DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See
https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
解决办法:
[root@dbmon ~]# vi /etc/profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
[root@dbmon ~]# source /etc/profile
在脚本前面添加 source /etc/profile
[oracle@dbmon ~]$ crontab -e
#######Tablespace Monitor######
13 14 * * * source /etc/profile && /usr/local/bin/python3 /dbmon/script/Check_tablespace_usage.py > /dbmon/script/log/Check_tablespace_usage.log 2>&1
或者直接crontab -e里添加环境变量,注意:变量前不能使用$符号,否则识别不了。如:$ORACLE_HOME,crontab不会识别
[oracle@dbmon ~]$ crontab -e
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/19.3.0/db_1
LD_LIBRARY_PATH=/u01/app/oracle/product/19.3.0/db_1/lib
#######Tablespace Monitor######
#24 14 * * * source /etc/profile && /usr/local/bin/python3 /dbmon/script/Check_tablespace_usage.py > /dbmon/script/log/Check_tablespace_usage.log 2>&1
55 14 * * * /usr/local/bin/python3 /dbmon/script/Check_tablespace_usage.py > /dbmon/script/log/Check_tablespace_usage.log 2>&1
~