前提:nginx装在linux的,linux 安装了cron

背景:nginx日志会逐步累积,定期清理需求

Linux 定时清理nginx方法及脚本

编写.sh脚本,其中clearNginxLog.sh是清理脚本,我把它放在了nginx安装目录下

Linux 定时清理nginx方法及脚本

backupdir=/usr/local/nginx/logs
truncate -s 0 $backupdir/error.log
truncate -s 0 $backupdir/access.log

新上传的sh文件可能没有权限运行,执行:

chmod a+x /usr/logcal/nginx/sh/clearNginxLog.sh

 

然后执行:crontab-e ,其中#!/bin/bash 和脚本中的/bin/sh是申明脚本sh方式允许

Linux 定时清理nginx方法及脚本

保存后,crontab -l 查看,如此就搞定了 

相关文章:

  • 2021-12-02
  • 2021-10-24
  • 2021-07-29
  • 2021-10-25
  • 2021-06-11
  • 2021-10-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-03-05
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案