CRON和SQLPLUS [英] CRON and SQLPLUS
问题描述
我想在cron中运行一个包含一些sqlplus命令的脚本。
I want to run a script, which contains some sqlplus commands, in cron.
问题是,由于某种原因,不会执行sqlplus命令,在cron中执行时。如果我自己执行脚本,脚本可以正常运行。
The problem is, that the sqlplus command won't be executed for some reason, when executed in cron. If I execute it by myself, the script runs fine.
我已经检查了一些论坛,甚至包括stackoverflow.com上的主题,并找到了有关正确设置的一些提示。环境变量。但是,即使经过仔细检查,该脚本也不起作用。
I've checked some forums, even the topics here on stackoverflow.com and found some tips regarding the correct setting of environment variables. But even after double checking this, the script doesn't work.
这是我的脚本:
echo $ORACLE_HOME|grep "oracle" > /dev/null
if [ $? = 1 ] ; then
echo "Setting environment variable"
# Setting oracle environmet
. /usr/oracle/product/10.2.0/.profile
NLS_LANG='AMERICAN_GERMANY.WE8ISO8859P1'
fi
/usr/oracle/product/10.2.0/bin/sqlplus username/password @basics.sql > export.file
basics.sql包含:
basics.sql contains:
set pagesize 0
set feedback off
set heading off
set linesize 400
set NULL nll
SELECT SOME_FIELDS FROM TABLE ORDER BY FIELD;
EXIT;
有什么想法吗?
推荐答案
shell环境对Oracle非常重要,使用cron时几乎没有。与往常一样,有几种方法可以解决此问题。
shell environment is very important for Oracle and almost not there when using cron. As always there are several ways to solve this.
- 使用完全限定的路径-有点不灵活
- 使脚本设置为自己的执行环境
- 在调用脚本时在cron中设置执行环境。
使用脚本来设置环境的一种非常标准的方法是使用oraenv脚本,该脚本通常位于/ usr / local / bin
A pretty much standard way of setting up your environment from withing the script is by using the oraenv script, normally located in /usr/local/bin
ORACLE_SID={your_sid}
ORAENV_ASK=NO
type oraenv >/dev/null 2>&1 || PATH=/usr/local/bin:$PATH
. oraenv
SQLPATH=$HOME/sql
export SQLPATH
do your stuff
从cron行:
10 10 * * * $HOME/.profile;$HOME/bin/your_script >$HOME/log/your_script.log 2>&1
这假定.profile是不互动,并导出所需的环境。
This assumes that the .profile is not interactive and export the needed environment.
这篇关于CRON和SQLPLUS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!