Mail to my account after jobs completion
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Mail to my account after jobs completion

  1. #1
    Join Date
    May 2000
    Location
    fremont ca
    Posts
    182

    Red face

    Hi!
    1. I want to send mail to my yahoo account as soon as my script or job executed in unix ? I saw unix mail and mailx command which sent mail in unix user. I want to send electronics mail to my account.
    Can any body giude me ?
    2. Is there any way if in my shell script I am executing many oracle command one by one , I want to send mail when error occurs in job only.

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,095
    You can use a ksh script similar to the one below. Just make sure that you include "WHENEVER SQLERROR EXIT SQL.SQLCODE" as one of the first few lines of your SQL script. This will ensure that you get a non-zero status when an error occurs.

    ======doit.ksh======
    #!/bin/ksh

    logfile=/tmp/log.$$

    exec > $logfile 2>&1
    sqlplus -s username/password@db @doit.sql
    let res=$?
    if (( $res != 0 )) ; then
    ___mailx -s "the subject" myEmail@excite.com < $logfile
    fi
    ====end of doit.ksh====

    ====doit.sql=====
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    select count(*) from dba_objects
    /
    exit
    ====end of doit.sql=====
    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."

  3. #3
    Join Date
    Apr 2000
    Posts
    126

    Wink

    Here is an example. I have a script that looks for a certain kind of db lock. A sql script finds the locks and creates another sql script to kill them. The information is e-mailed to me. The following is the shell script:

    BASE_LOC=/P0/app/oracle/admin/scripts
    . $BASE_LOC/ora_env.sh
    DBA='user@whatever.com'

    /P0/app/oracle/product/8.1.5/bin/sqlplus -s xxxxx/xxxxx << EOF
    @/P0/app/oracle/admin/scripts/pr_locks.sql
    quit
    EOF

    cat /tmp/kill_sessions.sql >> /tmp/pr_locks.lst
    cat /tmp/kill_sessions.lst >> /tmp/pr_locks.lst
    cat /tmp/pr_locks.lst | mailx -s "PR Locks Killed" $DBA

    rm /tmp/pr_locks.lst
    rm /tmp/kill_sessions.sql
    rm /tmp/kill_sessions.lst

  4. #4
    Join Date
    May 2000
    Location
    fremont ca
    Posts
    182
    Hi! Thanks
    But I am executing import and export utility how can I trap error in that ?

  5. #5
    Join Date
    Apr 2000
    Posts
    126
    # Check the export log for errors
    ERRFILE=/tmp/daily_export_$ORACLE_SID
    for logs in `ls -t /usr04/exports/$ORACLE_SID/log | head -1`
    do
    grep "ORA-" $logs > $ERRFILE
    if [ -s $ERRFILE ]
    then
    mailx -s "Export Errors for database $ORACLE_SID" dbadmin < $ERRFILE
    else
    mailx -s "No export errors today for database $ORACLE_SID" dbadmin < /dev/null
    fi
    rm $ERRFILE
    done

Posting Permissions

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



Click Here to Expand Forum to Full Width