Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###
- #This is a script intended to be used on chatty environments that frequently run
- #out of disk space. Please choose the file age carefully. Once the file is gone its gone.
- #For support on this script please contact John.DeConti@kuehne-nagel.com
- #****IF YOU DO USE THIS SCRIPT PLEASE MODIFY THE VARIABLES FOR LOCATION AND A******
- ################################
- # _.-^^---....,,-- ####
- # _-- --_ ####
- #< >)####
- #| |####
- # \._ _./ ####
- # ```--. . , ; .--''' ####
- # | | | ####
- # .-=|| | |=-. ####
- # `-=#$%&%$#=-' ####
- # | ; :| ####
- # _____.,-#%&$@%#&#~,._____ ####
- ################################
- ##Variables
- log=/var/log
- Nukelocation=/var/spool/cups/ ###Which Directory needs to be cleaned
- timestamp=$(date +%Y%m%d_%H%M)
- filename=Log_Nuke_$timestamp.txt
- output=$log/$filename
- a=+2 ###Age of Files to be deleted i.e. +2, files older than 2 days
- ##Business End of Script
- echo "SpoolCleanup Beginning Standby -- $(date +%Y%m%d_%H%M)" >> $output
- echo "##########" >> $output
- echo "File Count Before Cleanup $Nukelocation" >> $output
- ls -la $Nukelocation |wc -l >> $output
- echo "##########" >> $output
- echo "Files to be DELETED." >> $output
- find $Nukelocation -mtime $a >> $output
- echo "##########" >> $output
- START_TIME=$(date +%s)
- echo "##########" >> $output
- find $Nukelocation -mtime $a -type f -exec rm {} \;
- END_TIME=$(date +%s)
- echo "##########" >> $output
- ELAPSED_TIME=$(expr $END_TIME - $START_TIME)
- echo "##########" >> $output
- echo "File Count After cleanup $Nukelocation" >> $output
- ls -la $Nukelocation |wc -l >> $output
- echo "##########" >> $output
- echo "Script Deployed Standby :: Script End -- $(date +%Y%m%d_%H%M)" >> $output
- echo "##########" >> $output
- echo "Elapsed Time :: $(date -d 00:00:$ELAPSED_TIME +%Hh:%Mm:%Ss)" >> $output
- echo "##########" >> $output
- echo "Files that could NOT be deleted" >> $output
- find $Nukelocation -mtime $a >> $output
- echo "##########" >> $output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement