Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76

    Unanswered: Problem running expdp in a cron job

    I wrote a script named $PATH_TO_SCRIPT/export.sh (the file is executable by everyone using chmod a+x). For some unknown reason I'm unable to run that script in a cronjob. I can run the script on the command line. Here's what I have in the script:
    Code:
    #!/bin/sh
    
    ORACLE_BASE=/u01/app/oracle
    ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1
    ORACLE_SID=avmv3
    
    $ORACLE_HOME/bin/expdp system/PASSWORD dumpfile=`date +%Y-%m-%d`_expdat.dmp directory=dpump_dir tablespaces=users content=data_only;
    In crontab, the command looks like
    $PATH_TO_SCRIPT/export.sh >> /home/oracle/exp.log 2>&1

    after the cron job runs, the file exp.log would be empty.

    Anyhow, how could I run the script on a scheduled basis using cron?
    Last edited by unicef2k; 02-11-05 at 11:38. Reason: Forgot to ask question at the end
    System: Oracle 10g on Fedora Core 1

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Your environment variable $PATH_TO_SCRIPT may not be set when crontab tries to execute the script, replace this variable with the complete path if this is what you have coded in the crontab.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76
    $PATH_TO_SCRIPT is set to be the absolute path to the script.
    System: Oracle 10g on Fedora Core 1

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Where is $PATH_TO_SCRIPT set?
    Your crontab should have the absolute path like:
    Code:
    00 21 * * * /u01/app/oracle/scripts/export.sh >> /home/oracle/exp.log 2>&1
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76
    Quote Originally Posted by LKBrwn_DBA
    Where is $PATH_TO_SCRIPT set?
    Your crontab should have the absolute path like:
    Code:
    00 21 * * * /u01/app/oracle/scripts/export.sh >> /home/oracle/exp.log 2>&1
    That's exactly what I have
    System: Oracle 10g on Fedora Core 1

  6. #6
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking

    It seems not all your environment variables are set. Customize oraenv script or code an environment script to set these variables, something like this:
    Code:
    #!/bin/ksh
    ##################################################
    # $ORABIN/o817_env.ksh
    # Set Environment variables for Oracle RDBMS version 8.1.7
    ##################################################
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/10.1.0/db_1
    export JRE_HOME=$ORACLE_HOME/JRE
    export CLASSPATH=$JRE_HOME/lib:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib: $ORACLE_HOME/plsql/jlib:$ORACLE_HOME/ord/jlib:$ORACLE_HOME/network/jlib: $ORACLE_HOME/owm/jlib:$ORACLE_HOME/jdbc/lib:$ORACLE_HOME/ord/ts/jlib
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib: $ORACLE_HOME/jdbc/lib:$ORACLE_HOME/ctx/lib:$ORACLE_HOME/rdbms/lib:/usr/dt/lib:/usr/lib:/usr/openwin/lib
    export  ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
    export  ORACLE_PATH=$ORAWMD/lib:$ORACLE_HOME/bin
    export  ORACLE_TERM=vt100
    export  TMPDIR=/tmp
    export  TNS_ADMIN=$ORACLE_HOME/network/admin
    export  ORACLE_SID=avmv3
    ##################################################
    # Set Path
    ##################################################
    wc=$(echo $PATH|grep $ORACLE_HOME/bin|wc -l)
    if test wc -eq 0
    then
      export        PATH=$ORACLE_HOME/bin:$PATH
    fi
    And use it in your export.sh script (note the dot-space):
    Code:
    #!/bin/ksh
    . /u01/app/oracle/o817_env.ksh
    
    $ORACLE_HOME/bin/expdp system/PASSWORD dumpfile=`date +%Y-%m-%d`_expdat.dmp directory=dpump_dir tablespaces=users content=data_only;
    PS: Some variables are optional (like JRE_HOME) and others you must replace the example with your own library paths.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  7. #7
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76
    The script works now, I had to export
    ORACLE_BASE, ORACLE_HOME, and ORACLE_SID

    (My script wasn't working because I didn't export them)
    System: Oracle 10g on Fedora Core 1

  8. #8
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Thumbs up

    Good Job!
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •