A script to find out tar.gz files and notify via email
- 
 Hi Guys, Have a project , which i am working on I have a couple of servers based on linux OS. 
 Users will leave backups as tar.gz files back and i need to find out and remove them.
 Need a script which searches and lists the tar.gz files in servers.
 And have written a script for this , but this will only give the path and filename.#Tar Files in the server. rm -rf /home/tar.gz.txt 
 cd /home
 find . -size +1M -name "*.tar.gz" > /home/tar.gz.txt && mail -s 'Tar_File Report' email@mydomain
 < /home/tar.gz.txtThe output which i am planning to get is like the below . List of tar files with path from each server as a consolidated e-mail 
 An e-mail should be triggered every month (a cron can be set for this)
 The email should consist of the file path and a short note about the number of files and total size for the tar.gz files.can i get some help on this please . 
- 
 So you want to manually remove the .gz files on a monthly basis? 
- 
 Sounds like he just wants an email for now. 
- 
 @Ajin said: Remove cd /home and write your find statement like below: > find /home -size +1M -name "*.tar.gz"This is cleaner and easier to read and far, far safer in case of a typo or something. If that cd command failed for any reason your find would go haywire and potentially do bad things. 
- 
 If you change your script to this, it will remove the files automatically without needing to email them or tell anyone. #Tar Files in the server. find /home -size +1M -name "*.tar.gz" -exec rm -rf {} \;
- 
 Rather than automatically removing the files why not move the files into a directory that can be clean up later? While still emailing the original file location so if you have to restore you have a path to move them back to. 
- 
 @DustinB3403 said: Rather than automatically removing the files why not move the files into a directory that can be clean up later? While still emailing the original file location so if you have to restore you have a path to move them back to. find /home -size +1M -name "*.tar.gz" -exec mv {} /tmp/filestocleanup/ \;
- 
 Thanks for your valuable suggestions DustinB3403 & scottalanmiller. My goal is not to remove the files immediately but to get a notification email, verify with team and cleanup upon confirmation. 
- 
 @Ajin said: Thanks for your valuable suggestions DustinB3403 & scottalanmiller. My goal is not to remove the files immediately but to get a notification email, verify with team and cleanup upon confirmation. Okay, so no automatic removal. 
- 
 Yes , No automated removals. 



