The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Possible to search for a specific file, then e-mail me if found?

Discussion in 'E-mail Discussions' started by noimad1, Nov 5, 2005.

  1. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    I am wondering if there is a way to do lets say a "locate" every night, and if a specific file is found, I could get an e-mail that tells me where it was found?

    I am sure there is a simple perl script that can be written to do this, but I don't know perl at all. Anyone know how I can do this?

    I know this isn't really a cpanel issue, but everyone is usually so helpfull I thought I would give it a shot...
     
  2. Zaf

    Zaf Well-Known Member

    Joined:
    Aug 22, 2005
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    The following command maybe added as cron
    locate filename | mail -s "File found" email@domain.tld

    hth
     
  3. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Awesome, I will give that a try. I new that there would be an easy solution...
     
  4. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16

    Hmmmmmm.....I guess I thought about it and would need a little more functionality. I don't want to receieve an e-mail unless that file was found.....?
     
  5. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
  6. asmithjr

    asmithjr Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    475
    Likes Received:
    1
    Trophy Points:
    18
    filefind

    this will do the job I think you are looking for

    Code:
    #!/bin/sh
    
    # filefind.sh - locate files then send mail to admin if files found
    
    filename=".contactemail"             # change to file you are looking for
    email="admin@domain.com"             # change to email you want to send to
    tmpfile="/tmp/filefind"
    
    # Locate the files and write to temp file
    locate $filename > $tmpfile
    RC=$?
    if [ $RC = 0 ]
    then
            mail -s "File found" $email < $tmpfile
    fi
    
    # Clean up temp file
    rm $tmpfile
    
    #
    # End
    #
    
     
  7. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    perfect, I think that will get th job done. I appreciate your help even though it was non-cpanel related....

    Regards,
    Damion
     
Loading...

Share This Page