Created
          November 30, 2012 05:57 
        
      - 
      
- 
        Save coldfire-x/4174003 to your computer and use it in GitHub Desktop. 
    nginx rotate log, remove archive logs older than 2 weeks
  
        
  
    
      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/bash | |
| ARVDATE=`date +%Y%m%d%H%M` | |
| PID=/usr/local/nginx/nginx.pid | |
| cd /usr/local/nginx/logs | |
| for log in sdf.access.log error.log | |
| do | |
| file=lastweek/arv$log$ARVDATE.log | |
| mv $log $file | |
| kill -USR1 `cat $PID 2>/dev/null` 2>/dev/null | |
| gzip $file | |
| # remove files older than 14days | |
| find /usr/local/nginx/logs/lastweek/ -type f -mtime +14 -exec rm '{}' \; | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment