#!/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. html-prepend

    $('.classDiv').prepend('<span>添加</span>')

  2. Failed to execute request because the App-Domain could not be created. Error: 0x80070002 系统找不到指定的文件。

    360更新补丁后,网站就打不开aspx文件了,后来一查是framework2.0的KB2844285这个补丁引起的.把它卸载掉就ok了!          

  3. error C2011: “timespec”:“struct”类型重定义

    error C2011: “timespec”:“struct”类型重定义 C++ pthread pthread.h 中的 timespec 和time.h 中的 结构定义重复了 ,同时两个头文件中 ...

  4. IntelliJ IDEA 注释模板设置

    1.idea类注释 打开:file->setting->Editor->Filr and Code Templates->Includes->File Header 类注 ...

  5. Flex4学习笔记1---基本语法

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  6. out.println与<%!%>的功能一样

    <%! public static final String DBDRIVER = "A"; public static final String DBURL = " ...

  7. Python基础2 列表 字典 集合

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...

  8. Mysql 索引 n-gram分词引擎使用

    概述: 类似于书籍的目录,找到一本书的特定内容,需要首先找到内容对应页码,定位对应页码 存储引擎使用类似方法进行数据查找,先找到索引中对应值,然后根据匹配的索引找到对应行 实现原理: 索引的实现通常使 ...

  9. python 3.4 error: Microsoft Visual C++ 10.0 is required(Unable to find vcvarsall.bat)

    一些小技巧 我是在windows 64下安装的python3.4 Python 我在安装theano时报这个错,网上找了不少资料.自己摸索着解决了. 你先打开dos界面.我用set命令查看一下: 发现 ...

  10. Linux 远程登录配置

    如果使用FlashFxp的sftp无法登陆,提示SSH 错误: 协商认证模式失败,也同样这样操作 修改你的ssh配置文件 配置文件路径如:/etc/ssh/sshd_config PasswordAu ...