创建脚本文件
vim /home/oracle/script/rmanclear.sh
#!/bin/bash
DATE=`date "+%Y-%m-%d"`
/u01/app/oracle/product/db/bin/rman target sys/oracle << EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time ‘sysdate-1‘;
exit;
EOF
if [ $? -eq 0 ]
then
echo " $DATE clear rmanlog is successful. " >> /home/oracle/script/rmanclear.log
else
echo " $DATE clear rmanlog is failed. " >> /home/oracle/script/rmanclear.log
fi
赋予可执行权限
chmod 777 /home/oracle/script/rmanclear.sh
创建日志文件记录,并赋予写权限
touch /home/oracle/script/rmanclear.log
chmod a+w /home/oracle/script/rmanclear.log
切换回root加入计划任务
crontab -e
30 00 * * * su - oracle -c ‘/home/oracle/script/rmanclear.sh‘
时间: 2024-11-05 11:37:59