Advertisement
Guest User

Filecleaner

a guest
Jul 25th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###
  4. #This is a script intended to be used on chatty environments that frequently run
  5. #out of disk space. Please choose the file age carefully. Once the file is gone its gone.
  6. #For support on this script please contact John.DeConti@kuehne-nagel.com
  7.  
  8. #****IF YOU DO USE THIS SCRIPT PLEASE MODIFY THE VARIABLES FOR LOCATION AND A******
  9.  
  10. ################################
  11. # _.-^^---....,,-- ####
  12. # _-- --_ ####
  13. #< >)####
  14. #| |####
  15. # \._ _./ ####
  16. # ```--. . , ; .--''' ####
  17. # | | | ####
  18. # .-=|| | |=-. ####
  19. # `-=#$%&%$#=-' ####
  20. # | ; :| ####
  21. # _____.,-#%&$@%#&#~,._____ ####
  22. ################################
  23.  
  24.  
  25.  
  26. ##Variables
  27. log=/var/log
  28. Nukelocation=/var/spool/cups/ ###Which Directory needs to be cleaned
  29. timestamp=$(date +%Y%m%d_%H%M)
  30. filename=Log_Nuke_$timestamp.txt
  31. output=$log/$filename
  32. a=+2 ###Age of Files to be deleted i.e. +2, files older than 2 days
  33. ##Business End of Script
  34. echo "SpoolCleanup Beginning Standby -- $(date +%Y%m%d_%H%M)" >> $output
  35. echo "##########" >> $output
  36. echo "File Count Before Cleanup $Nukelocation" >> $output
  37. ls -la $Nukelocation |wc -l >> $output
  38. echo "##########" >> $output
  39. echo "Files to be DELETED." >> $output
  40. find $Nukelocation -mtime $a >> $output
  41. echo "##########" >> $output
  42. START_TIME=$(date +%s)
  43. echo "##########" >> $output
  44.  
  45. find $Nukelocation -mtime $a -type f -exec rm {} \;
  46.  
  47. END_TIME=$(date +%s)
  48. echo "##########" >> $output
  49. ELAPSED_TIME=$(expr $END_TIME - $START_TIME)
  50. echo "##########" >> $output
  51. echo "File Count After cleanup $Nukelocation" >> $output
  52.  
  53. ls -la $Nukelocation |wc -l >> $output
  54. echo "##########" >> $output
  55. echo "Script Deployed Standby :: Script End -- $(date +%Y%m%d_%H%M)" >> $output
  56. echo "##########" >> $output
  57. echo "Elapsed Time :: $(date -d 00:00:$ELAPSED_TIME +%Hh:%Mm:%Ss)" >> $output
  58. echo "##########" >> $output
  59. echo "Files that could NOT be deleted" >> $output
  60.  
  61. find $Nukelocation -mtime $a >> $output
  62. echo "##########" >> $output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement