如何设置crontab,定时归档删除7天之前的日志文件

土匪八号 2014-07-15 11:45:14
小弟向实现一下效果但是一直没有成功
采用crontab定时机制删除,每天定时压缩7天以前的文件,压缩之后再删除。
请各位大侠指点如何写脚本
...全文
5955 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_19049625 2014-08-07
  • 打赏
  • 举报
回复
先find出文件出来,然后备份清除
ljc007 2014-07-16
  • 打赏
  • 举报
回复
source /etc/profile
find /weblog10/bea/user_projects/log/task/schedule/ -name "*.log" -mtime +7 -exec tar cvf /weblog10/bea/user_projects/log/task/schedule/backup/task-`date "+%y%m%d"`.tar {} \;
find /weblog10/bea/user_projects/log/task/schedule/ -name "*.log" -mtime +7 -exec rm -f {} \;
把以上3行代码保存为 test.sh,依次执行下面两个命令: chmod +x test.sh ./test.sh 看看是否报错
  • 打赏
  • 举报
回复
there is a package called logrotate...
象大 2014-07-15
  • 打赏
  • 举报
回复
因为find -exec 参数默认是以 \; 结尾的。你的两条命令系统会以为是一条命令,所以报错。(个人猜测) 建议分开,间隔一段时间执行第二条。又不费事,也能减轻服务器压力。
土匪八号 2014-07-15
  • 打赏
  • 举报
回复
引用 2 楼 gpl369 的回复:
find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.log\" -mtime +5 -exec tar cvf /weblog10/bea/user_projects/log/task/schedule/backup/task-`date +\%y\%m\%d`.tar {} \; find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.tar\" -mtime +5 -exec rm -rf {} \;
我这边想实现的就是先压缩log后删除log,只是这两个依据单独执行可以执行,但是写到sh文件后就不能执行了
象大 2014-07-15
  • 打赏
  • 举报
回复
find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.log\" -mtime +5 -exec tar cvf /weblog10/bea/user_projects/log/task/schedule/backup/task-`date +\%y\%m\%d`.tar {} \; find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.tar\" -mtime +5 -exec rm -rf {} \;
土匪八号 2014-07-15
  • 打赏
  • 举报
回复
一下语句单独执行可以,为什么写到sh文件后,用sh 文件名.sh 就不能执行报如下错误 find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.log\" -mtime +5 -exec tar cvf /weblog10/bea/user_projects/log/task/schedule/backup/task-`date +\%y\%m\%d`.tar {} \; find /weblog10/bea/user_projects/log/task/schedule/ -name \"*.log\" -mtime +5 -exec rm -rf {} \; $ find: 0652-018 An expression term lacks a required parameter.

1,194

社区成员

发帖
与我相关
我的任务
社区描述
该论坛主要探讨IBM AIX平台的安装、部署、应用开发等话题,并为网友们提供自由交流的平台。
社区管理员
  • IBM AIX社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧