1.脚本代码:
[root@rac1 ~]# vi /home/oracle/delete_archive_log.sh
#!/bin/bash
oracle_sid=racdb1
oracle_home="/opt/app/oracle/product/11.2.0"
#ps -ef | grep oracle | grep -w "ora_lgwr_${oracle_sid}" >& /dev/null
#if [ $? -ne 0 ]
#then
# exit 0
#fi
#source $HOME/.bash_profile ## 必须有oracle的环境变量,否则会提示##Message file RMAN.msb not found
##Verify that ORACLE_HOME is set properly
##${oracle_home}/bin/rman 必须是全路径的,否则会报不认识RMAN这个命令
/opt/app/oracle/product/11.2.0/bin/rman target sys/sysPass << EOF
crosscheck archivelog all;
#delete noprompt obsolete;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-2';
exit;
EOF
~
2.设置自动执行:
[oracle@rac1 ~]$ crontab -l
30 01 * * * /home/oracle/delete_archive_log.sh
[oracle@rac1 ~]$
3.自动执行后的日志查看:
[root@rac1 ~]# vi /var/log/cron