Created
March 22, 2022 16:18
-
-
Save fanpero87/854f2d8932c306f8e3e82a71ab0ad86e to your computer and use it in GitHub Desktop.
This file contains 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Review
When copy this script, check and modify it as you require. Double check every line before run it.
Make the file executable
Run file