ITPub博客

首页 > 数据库 > Oracle > linux下设置邮件自动发送

linux下设置邮件自动发送

原创 Oracle 作者:peng163fj 时间:2015-07-13 13:45:32 0 删除 编辑
--设置自动任务
[oracle@db ~]$ crontab -l
1 1 * * * /var/monitor/db/backup_mail.sh

---设置发送邮件的主题hostname+rman_backup+日期
--调用
[oracle@db ~]$ more /var/monitor/db/backup_mail.sh
export LANG=en
/var/monitor/db/db.sh /var/monitor/db/1440
cat /var/monitor/db/log/rman.log |mail -s `hostname`"_rman_backup_"`date +%F_%H:%m` 1@163.com,2@163.com

--DB.SH
[oracle@db ~]$ more /var/monitor/db/db.sh 
if [ $# -ne 1 -o -z "${1}" ]; then
  echo "Usage : $0 TAGNAME"
  exit 1
fi
echo "Start Time: "`date +%Y-%m-%d_%H:%M:%S`
source /home/oracle/.bash_profile
PWD=$1
SQL="sqlplus / "\"as\ sysdba\"""
export PWD
export SQL
echo "Run SQL Scripts"
for line in `ls $PWD/*.sql`; do echo $SQL" @"$line; done|sh
echo "Run Shell Scripts"
for line in  `ls $PWD/ora*.sh`;do echo "sh "$line">> /var/monitor/db/log/db.log";done|sh
echo "End Time: "`date +%Y-%m-%d_%H:%M:%S`

--STATUS
[oracle@VM_76_4_centos 1440]$ ls
rman_backup_status.sql
[oracle@VM_76_4_centos 1440]$ more rman_backup_status.sql 
set linesize 200
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
col message for a50
set pagesize 999
spool '/var/monitor/log/rman.log'
select rs.OBJECT_TYPE||' '||rs.OPERATION||' '||rs.STATUS||'.'as message,rs.START_TIME||'~'||rs.END_TIME time
from v$rman_status rs
where rs.START_TIME>sysdate - 1
and rs.OPERATION like '%BACKUP%'
order by rs.START_TIME;
spool off;
exit
[oracle@VM_76_4_centos 1440]$ 



/etc/mail.rc

set from=发件人
set smtp=smtp.163.com
set smtp-auth-user=用户名
set smtp-auth-password=密码
set smtp-auth=login 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/21302630/viewspace-1731566/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 7-13工作
请登录后发表评论 登录
全部评论

注册时间:2013-11-20

  • 博文量
    155
  • 访问量
    440198