Last active
January 11, 2018 09:13
-
-
Save allex/10360845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script run at 00:00 | |
# 00 00 * * * /bin/bash /opt/soft/nginx/script/cutlog.sh | |
# 00 00 * * * /usr/sbin/tmpwatch -m 72 /data/soft/nginx/logs/ | |
# @author Allex Wang (http://iallex.com) | |
# <https://gist.github.com/allex/10360845> | |
# Set variable | |
logs_path="/var/log/nginx/" | |
old_logs_path=${logs_path}/old | |
nginx_pid=`cat /var/run/nginx.pid` | |
time_stamp=`date -d "yesterday" +%Y-%m-%d` | |
mkdir -p ${old_logs_path} | |
# Main | |
for file in `ls $logs_path | grep log$ | grep -v '^20'` | |
do | |
if [ ! -f ${old_logs_path}/${time_stamp}_$file ] | |
then | |
dst_file="${old_logs_path}/${time_stamp}_$file" | |
else | |
dst_file="${old_logs_path}/${time_stamp}_$file.$$" | |
fi | |
mv $logs_path/$file $dst_file | |
gzip -f $dst_file # do something with access.log.0 | |
done | |
kill -USR1 $nginx_pid | |
# vim: set sts=2 sw=2 ts=2: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment