您的位置:首页 > 运维架构 > Shell

Shell脚本 - 删除30天前log日志和detail表

2019-08-05 15:07 267 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_39864440/article/details/98488772
一、Shell 脚本的内容如下:

1、首先运行shell脚本,这里需要输入 SID ,也就是用户。

2、连接服务器,然后连接服务器上的 oracle 数据库,执行 sql 脚本,删除detail表。

3、进入到 log 日志存放的目录下:
• 获取当前时间。
• 获取30天之前的时间。
• 找到匹配30天之前的log文件并删除,这里我的log文件是已时间命名的。
• 提示成功或失败。

#!/bin/sh
if [ $# -lt 1 ]
then
echo "No SID."
exit
fi
SID=$1
host="10.129.2.30:1521/"${SID}
connection=dquser/dq2468@${host}
echo "SID:${host}"
echo "连接字符串:${connection}"
echo "-------------------------"
#sqlplus -S ${connection} @DQPurge.sql

#purge log files which are 90 days old
cd /home/gim/project/logs/

today=`date +%y%m%d`
date30=`date -d "30 days ago" +%y%m%d`
#date90=`date -d "90 days ago" +%y%m%d`
echo 'Today:'$today
echo '30DaysAgo:'$date30
#echo '90DaysAgo:'$date90
echo '--------------------------------------------------------'
echo 'Check(30DaysAgo):'
find -mtime +30 -name "*.log"
echo '--------------------------------------------------------'
#echo 'Check(90DaysAgo):'
#find -mtime +90 -name "*.log"
#echo '--------------------------------------------------------'
echo 'Delete...'
find -mtime +30 -name "*.log" -exec rm -rf {} \;
if [ $? -eq 0 ];then
echo "success"
else
echo "fail"
fi
二、Sql 脚本的内容如下:
detele from (select * from E_T_0001_DETAILS where update_dt=to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd'));
detele from (select * from B_T_0003_DETAILS where update_dt=to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd'));
detele from (select * from A_B_0003_DETAILS where update_dt=to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd'));
detele from (select * from B_B_0002_DETAILS where update_dt=to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd'));
detele from (select * from C_B_0001_DETAILS where update_dt=to_date(to_char(sysdate-30,'yyyy-mm-dd'),'yyyy-mm-dd'));
commit;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: