From 3d090cb405f9c62df6600d26f987490f0fe55333 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 20 Mar 2019 14:08:20 +0100 Subject: [PATCH] Redirecting output into logfiles --- sbin/cleanup-loghosts-hosts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sbin/cleanup-loghosts-hosts b/sbin/cleanup-loghosts-hosts index de09e85..2406c1c 100755 --- a/sbin/cleanup-loghosts-hosts +++ b/sbin/cleanup-loghosts-hosts @@ -7,6 +7,22 @@ if [[ ! -d "${HOSTS_DIR}" ]] ; then exit 5 fi +MY_LOG_DIR="${HOSTS_DIR}/zzz_cleanup_hostlogs" +if [[ ! -d "${MY_LOG_DIR}" ]] ; then + mkdir -m 0755 -p "${MY_LOG_DIR}" +fi + +i=0 +MY_LOG="${MY_LOG_DIR}/cleanup.$( date +'%Y-%m-%d' ).${i}.log" +ERR_LOG="${MY_LOG_DIR}/cleanup.$( date +'%Y-%m-%d' ).${i}.error.log" +while [[ -e "${MY_LOG}" || -e "${ERR_LOG}" ]] ; do + i=$(( $i + 1 )) + MY_LOG="${MY_LOG_DIR}/cleanup.$( date +'%Y-%m-%d' ).${i}.log" + ERR_LOG="${MY_LOG_DIR}/cleanup.$( date +'%Y-%m-%d' ).${i}.error.log" +done + +exec >> "${MY_LOG}" 2>> "${ERR_LOG}" + CUR_YEAR=$( date +'%Y' ) CUR_MONTH=$( date +'%m' ) @@ -209,11 +225,11 @@ compress_old_files() { echo echo "[$( my_date )]: Compressing files older than ${MIN_AGE_COMPRESS} days:" for fname in $( find "${HOSTS_DIR}" -type f -mtime +${MIN_AGE_COMPRESS} | \ - grep -vi '\.gz$' | head -n 1000 ) ; do + grep -vi '\.gz$' | head -n 10000 ) ; do if [[ -f "${fname}" ]] ; then echo " * '${fname}'" ls -l "${fname}" - gzip -v9 "${fname}" + gzip -9 "${fname}" ls -l "${fname}"* COMPRESSED_FILES=$(( $COMPRESSED_FILES + 1 )) fi -- 2.39.5