Skip to content

Instantly share code, notes, and snippets.

@fanpero87
Created March 22, 2022 16:18
Show Gist options
  • Save fanpero87/854f2d8932c306f8e3e82a71ab0ad86e to your computer and use it in GitHub Desktop.
Save fanpero87/854f2d8932c306f8e3e82a71ab0ad86e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# script to remove old files
# The folder path where the log files are
folder_path=/var/log/apache2/
# The location of where I want my script to log what it has done
log_of_files=/home/fongo/files_deleted.log
# Outputting the systems current date/time and then a line of hyphens into the log file
date >> $log_of_files
echo "---" >> $log_of_files
# Outputs the files that the find command finds and store them on the log_of_file file
# These will be the files that bash script will delete
# modification time greater than 100 days
find $folder_path -mtime +100 -name "*.gz" >> $log_of_files
# This line will delete the files
find $folder_path -mtime +100 -name "*.gz" -delete
# Adds another line of hyphens to the log file
echo "--- " >> $log_of_files
@fanpero87
Copy link
Author

Review

When copy this script, check and modify it as you require. Double check every line before run it.

Make the file executable

sudo chmod u+x delete_logs.sh

Run file

./delete_logs.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment