]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Redirecting output into logfiles
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 20 Mar 2019 13:08:20 +0000 (14:08 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 20 Mar 2019 13:08:20 +0000 (14:08 +0100)
sbin/cleanup-loghosts-hosts

index de09e85948691f4f0c567570b480f826378a0ba8..2406c1cec0adb5bd882a5ed53b155be38754b318 100755 (executable)
@@ -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