linux下設定郵件自動傳送

peng163fj發表於2015-07-13
--設定自動任務
[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部落格 ” ,連結:http://blog.itpub.net/21302630/viewspace-1731566/,如需轉載,請註明出處,否則將追究法律責任。

相關文章