added optional wildcard to archive logs

This commit is contained in:
Cryptoval Trading Technologies 2025-09-18 03:28:41 +00:00
parent 6567fd50d8
commit b7f60050b8

View File

@ -5,6 +5,7 @@ function usage {
echo -n " -L <log directory>"
echo -n " [ -A <archive_logs_dir> (default /works/archive/logs)]"
echo -n " [-D <older than time criteria> (default: '2 days ago')]"
echo -n " [-W <extra wild card> (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})