linux 日志设置定时清理

创建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 日志设置定时清理

上一篇:Linux系统根目录下各文件夹介绍


下一篇:ubuntu20下安装PyQt5及designer设计师