#! /bin/bash #This script allows for outdated logs to be deleted simply. echo "" echo "**************************************************************************" echo "This script will delete outdated logs. The following logs will be deleted." echo "" echo "1. Tomcat logs : Older than 60 days will be deleted" echo "2. T4 Publish logs: Older than 90 days will be deleted" echo "3. T4 Logs: Older than 90 days will be deleted" echo "**************************************************************************" echo "" echo "Current Disk usage:" echo "" df -h echo"" echo"" # counts how many outdated files have been found the log directories tomcatlog_count=$(find "/usr/share/tomcat9/logs/" -type f -mtime +60 | wc -l) t4publishlog_count=$(find "/web/terminalfour/publish-transfer-logs/" -type f -mtime +90 | wc -l) t4log_count=$(find "/web/terminalfour/logs/" -type f -mtime +90 | wc -l) #print message to use echo "Found the following:" echo "Outdated Tomcat logs: $tomcatlog_count" echo "Outdated T4 Publish logs: $t4publishlog_count" echo "Outdated T4 Logs: $t4log_count" echo "" echo "" read -p "Would you like to delete the outdated files that were found?? (yes/y): " choice if [[ "$choice" =~ ^[Yy](es)?$ ]]; then echo "Delete files..." find "/usr/share/tomcat9/logs/" -type f -mtime +60 -delete find "/web/terminalfour/publish-transfer-logs/" -type f -mtime +90 -delete find "/web/terminalfour/logs/" -type f -mtime +90 -delete echo "Files successfully deleted." else echo "Exiting. No further action taken." fi echo "Updated Disk usage:" echo "" df -h echo"" echo""