Skip to content

Commit

Permalink
created log file clean up script
Browse files Browse the repository at this point in the history
  • Loading branch information
davedavemckay committed Jul 2, 2024
1 parent bcd11e3 commit 5e70346
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/clean_up_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# This script is used to clean up log files in a specified folder.
# It checks if the log folder exists, counts the number of log files with a specific naming pattern,
# and deletes log files that are older than 1 day if doing so will leave at least two log files.

log_folder=$1

# Check if the log folder exists
if [ ! -d "$log_folder" ]; then
echo "Log folder does not exist."
exit 1

# Count files with naming pattern "lsst-backup-logs-*.csv"
else
num_files=$(ls -1 $log_folder/lsst-backup-logs-*.csv 2>/dev/null | wc -l)
if [ $num_files -gt 2 ]; then
num_old=`find $log_folder -name "lsst-backup-logs-*.csv" -type f -mtime +1 | wc -l`
num_left=`expr $num_files - $num_old`
if [[ $num_left -gt 2 ]];
then
echo "Cleaning up $num_files log files..."
find $log_folder -name "lsst-backup-logs-*.csv" -type f -mtime +1 -exec rm -v {} \;
fi
echo "Log files cleaned up."
else
echo "No log files to clean up."
fi
fi

0 comments on commit 5e70346

Please sign in to comment.