-
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.
-
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=====
-
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
-
Hi! Thanks
But I am executing import and export utility how can I trap error in that ?
-
# 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