diff --git a/archive_logs.sh b/archive_logs.sh index a9ce3b3..e9bf4a0 100755 --- a/archive_logs.sh +++ b/archive_logs.sh @@ -5,6 +5,7 @@ function usage { echo -n " -L " echo -n " [ -A (default /works/archive/logs)]" echo -n " [-D (default: '2 days ago')]" + echo -n " [-W (default: '*.log.*')]" echo exit 1 } @@ -14,10 +15,10 @@ echo Starting $0 $* LogDir=${1} LogArchiveDir=/works/archive/logs DateCriteria="2 days ago" - +ExtraWildCard= # ---------------- cmdline -while getopts "A:L:D:" opt; do +while getopts "A:L:D:W:" opt; do case ${opt} in A ) LogArchiveDir=$OPTARG @@ -28,6 +29,9 @@ while getopts "A:L:D:" opt; do D ) DateCriteria=$OPTARG ;; + W ) + ExtraWildCard=$OPTARG + ;; \? ) echo "Invalid option: -$OPTARG" >&2 usage @@ -53,7 +57,16 @@ echo "Looking for log files older than '${DateCriteria}' in ${LogDir}" Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S') -Cmd="find ${LogDir}/ '(' -name '*.log' -o -name '*.log.*' ')' -type f -not -newermt \"${Oldest}\"" +Cmd="find ${LogDir}/" +Cmd+=" '('" +Cmd+=" -name '*.log'" +Cmd+=" -o -name '*.log.*'" +if [ "${ExtraWildCard}" != "" ]; then + Cmd+=" -o -name '${ExtraWildCard}'" +fi +Cmd+=" ')'" +Cmd+=" -type f" +Cmd+=" -not -newermt \"${Oldest}\"" echo $Cmd files=$(eval ${Cmd})