-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurge.sh
26 lines (20 loc) · 959 Bytes
/
purge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
###########################################################################
# this script purges all log and backup files older than 30 days (by default)
# either change the value of days below or call the script with a parameter
# e.g., `/opt/YAMon3/purge.sh 14` to delete all logs & backups create more
# that 2 weeks ago.
# adding this as cron job is left as an exercise :-)
days=$1
[ -z "$days" ] && days=30
d_baseDir=$(cd "$(dirname "$0")" && pwd)
lfname="${d_baseDir}/logs/purge.log"
[ ! -f "$lfname" ] && touch "$lfname"
ds=$(date +"%Y-%m-%d %H:%M:%S")
echo "$ds - purging logs & backups for past $days days" >> "$lfname"
find "${d_baseDir}/logs/" -name *.log -mtime +$days -exec rm -f {} \;
find "${d_baseDir}/daily-bu2/" -name *.tar -mtime +$days -exec rm -f {} \;