Created
May 16, 2025 10:55
-
-
Save arpitr/303f0d3ae88afd47ad525432723d3db1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Log file path | |
LOG_FILE="logfile-name.txt" | |
# Function to log messages with timestamp | |
log_message() { | |
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE" | |
} | |
# Array of directories to process | |
directories=( | |
"twig-2025-03-17-00-00-04" | |
) | |
# Loop through each directory and delete files, logging after each deletion | |
for dir in "${directories[@]}"; do | |
if [ -d "$dir" ]; then | |
log_message "Starting file deletion in directory: $dir" | |
# Deleting files in the directory | |
find "$dir" -depth -type f -exec rm -f {} \; | |
# Check if files were successfully deleted | |
if [ $? -eq 0 ]; then | |
log_message "Successfully deleted files in directory: $dir" | |
else | |
log_message "Error occurred while deleting files in directory: $dir" | |
fi | |
else | |
log_message "Directory $dir does not exist. Skipping..." | |
fi | |
done | |
nohup ./cleanup_activity_9.sh > logfile-script.log 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment