Created
February 23, 2015 15:51
-
-
Save hsinhoyeh/9d410621fcb67390c08e 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/bash | |
| #setup a threshold which we are begining to clean the old files if the usage exceeds this threahold | |
| THRESHILD=80 | |
| # find out the current uage in the file system, especiallyfor /de/sda1 | |
| # /dev/sda1 197G 143G 45G 77% / | |
| # then we have 77 in CURRENT | |
| CURRENT=$(df -P | grep /dev/sda1 | awk '{ print $5}' | sed 's/%//g') | |
| # LOGFOLDER is the folder containing daily logs | |
| LOGFOLDER=/mnt/extend-disk/ | |
| if [ $CURRENT -lt $THRESHOLD ]; then | |
| echo "normal exist" | |
| exit 0 | |
| fi | |
| #begin clean files which are older than 7 days | |
| echo "begin clean files which are older than 7 days" | |
| # find out the log path, in this example, we have _tmp as the suffix of our log folder. | |
| LOGPATH=$(ls $LOGFOLDER | grep _tmp) | |
| # use -mtime +7 to indicate we are finding files which are 7 day old. | |
| find $LOGFOLDER$LOGPATH -mtime +7 -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment