Linux 定时清理nginx方法及脚本
前提:nginx装在linux的,linux 安装了cron
背景:nginx日志会逐步累积,定期清理需求
编写.sh脚本,其中clearNginxLog.sh是清理脚本,我把它放在了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方式允许
保存后,crontab -l 查看,如此就搞定了