cat clearLog.sh
export ORACLE_HOME=/path/rdbms/12c/12.1.0.2.160119
export SHELL_PATH=/etc/paic/shell
export XDG_SESSION_ID=283283
export HOSTNAME=cnsh281177
export SHELL=/bin/bash
export TERM=vt100
export HISTSIZE=1000
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_DOC=/path/rdbms/doc
export OLDPWD=/path/rdbms/toracle
export USER=toracle
export LD_LIBRARY_PATH=:/path/rdbms/12c/12.1.0.2.160119/lib:/paic/app/t0parebi/goldengate:/path/rdbms/12c/12.1.0.2.160119/lib
export ORACLE_SID=t0parebi
export ORACLE_BASE=/path/rdbms
export TMOUT=1800
export GGS_HOME=/paic/app/t0parebi/goldengate
export MAIL=/var/spool/mail/toracle
export PATH=/path/rdbms/12c/12.1.0.2.160119/bin:/path/rdbms/toracle/sh:/oracle_grid/12.1.0/grid/bin:/sbin:/usr/sbin:/opt/VRTS/bin:/opt/VRTSvcs/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/paic/app/t0parebi/goldengate
export ORA_ENCRYPT_LOGIN=true
export PWD=/path/rdbms/toracle/zad
export EDITOR=vi
export LANG=en_US
/path/rdbms/12c/12.1.0.2.160119/bin/rman nocatalog log /path/rdbms/toracle/zad/del_arch`date +%Y%m%d`.log <<EOF
connect target /
#crosscheck archivelog all;
#delete noprompt expired archivelog all;
DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-2';
exit;
EOF
2、编写crontab
crontab -l
53 09 * * * /path/toracle/zad/clearLog.sh
注:
这里在调试程序时,手动运行脚本并不报错。
但通过crontab来调度的时,会出现问题。出错的日志,见/var/spool/mail/os用户
如下日志报错,可以看到是因为没有设置环境变量ORACLE_HOME,导致rman在执行操作时出错。
tail -20 /var/spool/mail/toracle
Message-Id: <20170710014601.3B21D1801010@cnsh281177.localdomain>Date: Mon, 10 Jul 2017 09:46:01 +0800 (CST)
Message file RMAN<lang>.msb not found
Verify that ORACLE_HOME is set properly