environment setup inside cron job
DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: environment setup inside cron job

  1. #1
    Join Date
    Jan 2002
    Posts
    474

    environment setup inside cron job

    I like to schedule a job to be run at 8:00pm every night, and I know very a little about cron
    job, basically I just want to get the exp of the database every night. Please correct me if I
    am wrong. I have the script as below:

    export ORACLE_SID=TEST

    exp system/manager file=/u02/backup/TEST/exp_TEST_full.dmp
    log=/u02/backup/TEST/exp_TEST_full.log full=y direct=y

    and this script is save as backup_TEST.sh and it located on:
    /home/oracle/TEST/backup_TEST.sh



    seem like I have problem with setting the environment in my script but I used the same command to set environment when I do stuffs on the server and it worked.

    Any advise of what command I should type inside the script????

    thanks

  2. #2
    Join Date
    Oct 2003
    Posts
    38
    Give
    #!usr/bin/ksh
    ORACLE_SID=TEST
    export ORACLE_SID
    exp system/manager file=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full.dmp
    log=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full.log full=y direct=

    Try out the above.

  3. #3
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    set your Oracle Home as well

    When a job runs through cron is does a su to oracle without picking up any of the the Oracle profile information so all environment variables must be set explicitly in the cron script

    steve
    I'm stmontgo and I approve of this message

  4. #4
    Join Date
    Jan 2002
    Posts
    474
    stmongo and prince_jr,

    per your advise below is my script:

    #!usr/bin/ksh
    ORACLE_SID=TEST
    export ORACLE_SID
    ORACLE_HOME=/home/oracle/product/9.2.0
    export ORACLE_HOME
    exp system/manager file=/u02/backup$ORACLE_SID/exp_$ORACLE_SID_full.dmp
    log=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full.log full=y direct=y


    so I save this as backup_TEST.sh and I tried to run ./backup_TEST and I got the error:

    [oracle@qhoudb03 mytest]$ ./backup_TEST
    bash: ./backup_TEST: bad interpreter: No such file or directory


    Please advise, what's wrong here

  5. #5
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Originally posted by ashley75

    #!usr/bin/ksh

    should be
    #!/bin/ksh

    or whatever your ksh shell is located.
    Code:
    #!/bin/ksh
    
    # setup the environment
    export ORACLE_SID=TEST
    export ORAENV_ASK=NO;
    . oraenv
    
    FILE_STUB=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full
    
    exp system/manager file=$FILE_STUB.dmp log=$FILE_STUB.log full=y direct=y
    or, alternatively, you can setup your environment in your crontab:
    10 0 * * * (/bin/ksh "export ORACLE_SID=TEST; export ORAENV_ASK=NO, . $HOME/.profile; $HOME/your_export_script_goes_here.ksh")
    Last edited by marist89; 10-24-2003 at 05:04 PM.
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  6. #6
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Also, you know if you don't know WHY export is a VERY poor method for a backup, use "Search".
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  7. #7
    Join Date
    Oct 2003
    Posts
    38
    run as
    ./backup_test.sh

    if that does not work just give
    backup_test.sh

    Give the full name if you are not running from current directy
    /home/oracle/TEST/backup_test.sh

  8. #8
    Join Date
    Oct 2003
    Posts
    38
    I hope it worked now ??

  9. #9
    Join Date
    Jan 2002
    Posts
    474
    Jeff and Prince_jr,

    I got my script working when I issue ./backup_TEST.sh and everything seems to work fine. Below is my script:


    #!/bin/bash
    # full backup TEST


    ORACLE_SID=TEST
    export ORACLE_SID
    ORACLE_HOME=/home/oracle/product/9.2.0
    export ORACLE_HOME

    exp system/manager file=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full.dmp log=/u02/backup/$ORACLE_SID/exp_$ORACLE_SID_full.log full=y direct=y


    and this file is saved in :/home/oracle/DBA_STUFFS/backup_scripts/TEST/backup_TEST.sh


    but I seem to have problem when I schedule this job to be run at 8:00pm every night.


    below is the message I got in the mail:

    From: root@localhost.localdomain (Cron Daemon)
    To: oracle@localhost.localdomain
    Subject: Cron /home/oracle/scripts/backup/TEST/backup_TEST.sh
    X-Cron-Env: