ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    A script to find out tar.gz files and notify via email

    IT Discussion
    4
    10
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AjinA
      Ajin
      last edited by Ajin

      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.txt

      The 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 .

      scottalanmillerS 2 Replies Last reply Reply Quote 2
      • DustinB3403D
        DustinB3403
        last edited by

        So you want to manually remove the .gz files on a monthly basis?

        1 Reply Last reply Reply Quote 0
        • DashrenderD
          Dashrender
          last edited by

          Sounds like he just wants an email for now.

          1 Reply Last reply Reply Quote 0
          • scottalanmillerS
            scottalanmiller @Ajin
            last edited by

            @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.

            1 Reply Last reply Reply Quote 1
            • scottalanmillerS
              scottalanmiller @Ajin
              last edited by

              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 {} \;
              
              1 Reply Last reply Reply Quote 1
              • DustinB3403D
                DustinB3403
                last edited by DustinB3403

                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.

                scottalanmillerS 1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller @DustinB3403
                  last edited by

                  @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/ \;
                  
                  1 Reply Last reply Reply Quote 1
                  • AjinA
                    Ajin
                    last edited by

                    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.

                    scottalanmillerS 1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller @Ajin
                      last edited by

                      @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.

                      1 Reply Last reply Reply Quote 0
                      • AjinA
                        Ajin
                        last edited by

                        Yes , No automated removals.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post