定期删除日志

BBigSun 评论282阅读模式

Nacos 日志太多,写个脚本定期删除一下。

1、创建脚本 delete_log.sh

$ vi /opt/delete_log.sh

#!/bin/bash
find /opt/nacos/bin/logs/ -mtime +30 -name "*.log" -exec rm -rf {} \;

2、增加可执行权限

$ chmod +x delete_log.sh

3、添加定时任务

$ crontab -e 

59 23 * * * /opt/delete_log.sh >/dev/null 2>&1

4、crontab 选项

  • -u 指定一个用户
  • -l 列出某个用户的任务计划
  • -r 编辑某个用户的任务(不添加用户即删除所有任务)
  • -e 编辑某个用户的任务

5、cron 文件语法

# 举个栗子:每天23点59执行命令 /opt/delete_log.sh >/dev/null 2>&1
59 23 * * * /opt/delete_log.sh >/dev/null 2>&1

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
文章源自十年又十年-https://www.bbigsun.com/72.html文章源自十年又十年-https://www.bbigsun.com/72.html

纸上得来终觉浅,绝知此事要躬行。

weinxin
17688689121
我的微信
微信扫一扫
BBigSun
  • 本文由 BBigSun 发表于 2022年 11月 24日 08:56:57
  • 转载请务必保留本文链接:https://www.bbigsun.com/72.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定