zoukankan      html  css  js  c++  java
  • linux 日志设置定时清理

    创建shell 脚本命令:

    root@2290b60f3ac6:~# cat clearlog.sh 
    find /var/lib/postgresql/data/log/ -mtime +10 -name "*" -exec rm -rf {} ; 
    
    这个命令是find的基本用法,可以分两部分,find ~/ -name "*.aic"和 -exec rm -rf {} ;
     ~/:在根目录下查找
     -name 查找文件名的方式
     "*.aic"文件名中要求后缀是aic的所有文件
    -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 //重新载入配置 
    
    
  • 相关阅读:
    MySql插不进中文,以及IDEA连接MySql出现小段乱码问题
    安装Consul环境并启动
    格式化日期,首字母大写
    设计模式
    用户刷新页面,中止客户端面请求,怎么判断服务端也取消请求
    Token使用
    IdentityServer4搭建和使用
    Filter 过滤器
    添加Filter 并控制它的执行顺序
    在startup 添加数据库链接字符串
  • 原文地址:https://www.cnblogs.com/qianxunman/p/13337887.html
Copyright © 2011-2022 走看看