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;
相关文章推荐
- shell脚本:定期删除日志文件
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
- shell脚本统计nginx访问日志access.log
- linux 定期删除spark日志 shell 脚本
- linux脚本shell删除N天的日志find -mtime -exec
- 日志定时压缩清理shell脚本(日志文件后缀格式如xxxxx.log.2017-07-10)
- shell中自动切换用户删除日志小脚本
- linux下的shell脚本分割nginx日志并且删除三十天范围外的其他日志
- shell脚本删除旧日志文件
- 使用RMAN和控制文件备份删除归档日志的SHELL脚本--RED HAT 5 LINUX 64
- shell脚本删除旧日志文档
- 小shell脚本-----每周压缩日志文件并删除未压缩的文件
- 通过shell脚本定期删除linux用户下的日志
- shell脚本实现:每周 5 使用 tar 命令备份/var/log 下的所有日志文件
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
- shell脚本 定期删除日志
- 自动删除指定时间内的日志和文件shell脚本
- shell脚本自动删除n天前日志
- shell脚本检查统计nginx访问日志access.log
- 使用RMAN和控制文件备份删除归档日志的SHELL脚本--RED HAT 5 LINUX 64