CRON and SQLPLUS

前端 未结 1 1244
鱼传尺愫
鱼传尺愫 2021-01-25 04:52

I want to run a script, which contains some sqlplus commands, in cron.

The problem is, that the sqlplus command won\'t be executed for some reason, when executed in cron

相关标签:
1条回答
  • 2021-01-25 05:40

    shell environment is very important for Oracle and almost not there when using cron. As always there are several ways to solve this.

    1. use full qualified paths - a bit inflexible
    2. make the script to setup it's own execution environment
    3. setup the execution environment in cron, when calling the script.

    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
    

    from the cron line:

    10 10 * * * $HOME/.profile;$HOME/bin/your_script >$HOME/log/your_script.log 2>&1
    

    This assumes that the .profile is not interactive and export the needed environment.

    0 讨论(0)
提交回复
热议问题