#!/bin/bash
#author:skycheng #get current date string
datestr=`date +'%Y-%m-%d'`
start_time=`date +'%Y-%m-%d %H:%M:%S'` #get logfile name
logfile='/var/log/fs/drop_tables_'$datestr'.log' if [ ! -f $logfile ]
then
sudo touch $logfile
fi #drop tables table name:sms_send_log_X_yyyymmdd
do_drop_tables()
{
for table in $tables
do
#get table date 'yyyymmdd'
echo $table|grep sms_send_log>/dev/null >&
if [ $? -eq ]
then
table_date=${table:-}
if [ $table_date \< $drop_date ]
then
#echo $table
mysql -u$db_user -p$db_pass -h$db_host $database -e 'drop tables '$table >>$logfile
[ $? -eq ] && echo "drop table:"$table "success"|tee -a $logfile || echo "drop table:"$table "fail"
else
continue
fi
else
continue
fi
done
} echo starttime:$start_time>>$logfile #get three month ago date tables
drop_date=`date -d '3 month ago' +"%Y%m%d"`
echo 'drop_date='$drop_date db_user=dbuser
db_pass=dbpass #get all database tables on host db_host
db_host=db_host
database=database
tables=`mysql -u$db_user -p$db_pass -h$db_host $database -e 'show tables;'|sed 1d` do_drop_tables

shell脚本-删除当天日期前3个月的数据表的更多相关文章

  1. shell脚本删除N天前的目录-----附linux和mac上date命令的不同

    背景: 每日构建的东西.按日期放到不同的目录里. 现在天的构建放到2015-06-01里,明天的就放到2015-06-02里,依次类推.时间久了.须要一个脚本删除N天前的目录.(本例中N=7.即删除一 ...

  2. Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本

    说明:  1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...

  3. bat脚本删除一周前的文件

    bat脚本删除7天前的文件 @echo off forfiles /p D:\logstash-1.4.2\bin\ /m *.log -d -7 /C "cmd /c del /f @pa ...

  4. CentOS Linux自动备份MySQL数据库到远程FTP服务器并删除指定日期前的备份Shell脚本

    说明: 我这里要把MySQL数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2011_11_03.tar ...

  5. liunx 使用crontab定时任务+shell脚本删除tomcat日志elasticsearch日志索引

    由于过多的日志很占用磁盘空间,今天经理让我写一个脚本删除多余的日志.和es索引 定时删除试根据crontab+shell脚本实现的 crontab配置目录 /var/spool/cron/ 该目录下存 ...

  6. Linux shell 自动删除n天前日志

    linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情.不用你去每天惦记着是否需要清理日志 ...

  7. shell脚本删除log日志

    删除log文件简单shell脚本 经常会遇到日志把磁盘占满的情况,引起低级故障.我个人在实际工作中,尝试了如下的方法,比较简单,而且快捷有效. #!/bin/bash # /root/log_dele ...

  8. shell 自动删除n天前备份

    Linux自动删除n天前备份Linux是一个很能自动产生文件的系统,日志.邮件.备份等.因此需要设置让系统定时清理一些不需要的文件.语句写法:     find 对应目录 -mtime +天数 -na ...

  9. shell 脚本连接mysql数据库查询database中表的数量和表名

    #!/bin/bash MYSQLHOST="127.0.0.1" MYSQLUSER="root" MYSQLPWD="root" MYS ...

随机推荐

  1. [UGUI]修改顶点

    参考链接: https://blog.csdn.net/jk823394954/article/details/53870779 说明:unity版本5.3,新建一个Image,挂上以下的脚本 一.图 ...

  2. 使用NetBox实现ASP网页封装为EXE教程

    简单的形容就是把ASP文件打包 成一个EXE文件,并且不需要在调试的机器上安装IIS即可正常调试.如果按照说明书来操作的话,观看比较繁琐,本人为方便大家使用,现制作一个简单的使用教程. 封装过程 1. ...

  3. 36.scrapy框架采集全球玻璃网数据

    1.采集目标地址 https://www.glass.cn/gongying/sellindex.aspx 网站比较简单,没什么大的需要注意的问题.2.通过分析测试 https://www.glass ...

  4. git 常用操作总结

    廖雪峰博客的git 教程写得不错, 很详细,但是却总结的不是很好. 这里哥再详细总结一遍吧! Git鼓励大量使用分支: 查看分支:git branch 创建分支:git branch 切换分支:git ...

  5. 来分析一个UVC的摄像头的枚举信息

    使用到工具USBlyzer导出数据,但是会发现一些还有部分解析未完全.我们将借助UVCView.x86(https://files.cnblogs.com/files/libra13179/77772 ...

  6. 查看进程中的socket状态和数量

    程序运行时查看,结果是这样子的 C:\Users\Administrator>netstat -ano|findstr TCP TIME_WAIT TCP TIME_WAIT TCP TIME_ ...

  7. 为什么我希望用C而不是C++来实现ZeroMQ

    原文在这里 开始前我要先做个澄清:这篇文章同Linus Torvalds这种死忠C程序员吐槽C++的观点是不同的.在我的整个职业生涯里我都在使用C++,而且现在C++依然是我做大多数项目时的首选编程语 ...

  8. EmEditor

    姓 名:ttrar.com 序 列 号:DKAZQ-R9TYP-5SM2A-9Z8KD-3E2RK 免费版地址:https://zh-cn.emeditor.com/#download

  9. 使用python实现人脸检测<转载>

    原文地址:https://www.cnblogs.com/vipstone/p/8884991.html =============================================== ...

  10. UI5-学习篇-12-Eclipse同步ABAP服务器UI5应用

    如何在ABAP服务器上部署和运行SAPUI5应用程序 https://blogs.sap.com/2013/06/15/how-to-deploy-and-run-sapui5-application ...