Created
May 4, 2015 06:29
-
-
Save allex/c487d6d8b2b52219a87b 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 | |
# Auto cleanup expried log files. | |
# Author: Allex Wang ([email protected]) | |
# GistID: c487d6d8b2b52219a87b | |
# GistURL: https://gist.github.com/c487d6d8b2b52219a87b | |
log_dir=$1 # log files directory | |
expired_days=7 # log file expried days | |
function delete_logs() { | |
# get system unix datestamps | |
local current_date=`date +%s` | |
for f in `find $1 -name "*.log"` | |
do | |
local modify_date=$(stat -c %Y $f) | |
# calculate the modified date diffs | |
local exist_time=$(($(($current_date - $modify_date))/86400)) | |
if [ $exist_time -gt $expired_days ]; then | |
echo "Delete log file: $f, EXIST_TIME: ${exist_time}" | |
rm -f $f | |
fi | |
done | |
} | |
if [ -n "$log_dir" ]; then | |
delete_logs $log_dir | |
else | |
echo "logs dir not valid!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment