首页 > 系统服务 > 详细

linux 日志设置定时清理

时间:2020-07-19 00:07:29      阅读:69      评论:0      收藏:0      [点我收藏+]

创建shell 脚本命令:

root@2290b60f3ac6:~# cat clearlog.sh 
find /var/lib/postgresql/data/log/ -mtime +10 -name "*" -exec rm -rf {} \; 

创建定时执行计划:

  • 定时任务编辑命令: crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use ‘*‘ in these fields (for ‘any‘).#
# Notice that tasks will be started based on the cron‘s system
# daemon‘s notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

# 文件中加入该行,表示每天0点执行命令 `sh /root/clearlog.sh`
* 0 * * * sh /root/clearlog.sh

重启cron 服务:

/sbin/service crond start //启动服务 
/sbin/service crond stop //关闭服务 
/sbin/service crond restart //重启服务 
/sbin/service crond reload //重新载入配置 

linux 日志设置定时清理

原文:https://www.cnblogs.com/qianxunman/p/13337887.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!