+ -
当前位置:首页 → 问答吧 → 帮忙写个定时脚本

帮忙写个定时脚本

时间:2011-07-08

来源:互联网

本人刚接触mysql, 现在有个需求,定时删除上个月的日志记录,不是很清楚该如何写,大家能帮忙写个么?

比如,我自己写的这个,当然我知道这个执行不了的,语法不正确

#!/bin/sh
date=`date '+%Y%m%d'`
/usr/bin/mysql -uroot -p123456
delete from cpu where create_time<$date;

然后放crontab,每个月1号执行

作者: sghitwcw   发布时间: 2011-07-08

vi  /home/cleanlog.sh

[Copy to clipboard] [ - ]
CODE:
#!/bin/sh
NOW=`date '+%Y%m%d'`
echo $NOW >> /tmp/clean.log
/usr/bin/mysql -uroot -p123456  -e "use dbname; delete from cpu where create_time <$date " >>  /tmp/clean.log
echo -e "$1" >> /tmp/clean.log

vi /etc/crontab  添加

[Copy to clipboard] [ - ]
CODE:
42  4  1 *  * root /bin/sh home/cleanlog.sh > /dev/null 2>&1

[ 本帖最后由 wanan_YLF 于 2011-7-8 11:02 编辑 ]

作者: wanan_YLF   发布时间: 2011-07-08

非常感谢!

作者: sghitwcw   发布时间: 2011-07-08

相关阅读 更多

热门下载

更多