Find the answer to your Linux question:
Results 1 to 4 of 4
I'm a newb, but I'm wondering how hard it would be to do this: I have a server that I receive uploads to daily. I'd like to have a notification ...
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Location
    Allen, TX
    Posts
    1

    Email notification for new uploads to my RHEL server

    I'm a newb, but I'm wondering how hard it would be to do this:

    I have a server that I receive uploads to daily.

    I'd like to have a notification email sent to me telling me what files were uploaded and what time.

    The uploads are typically large zip files and are always uploaded to a single directory by just adding a new directory with a numerical value for date and month as the naming convention then adding the zip file in that location.

    Any help would be GREATLY appreciated.

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    It would be easy peasy.

    Write a cronjob that runs every minute (or whatever you prefer) that monitors that directory. Keep track of files in it with the use of a master list - just a text file containing each new file, one per line. A cronjob just means a scheduled run of whatever program you specify. In your case, it would be a simple bash script. An example of your script would be:
    Code:
    #!/bin/bash
    dirToWatch=/data/uploads
    masterList=${dirToWatch}/master.txt
    files=$(find $dirToWatch -maxdepth 2 -type f -name '*.zip')
    for file in $files; do
      grep -q $file $masterList
      if [ $? -eq 0 ]; then
        echo $file already in $masterList
      else
        # new file - add it to the list
        echo adding $file to $masterList
        echo $file >> $masterList
    
        # send message
        mail -s "new file $file uploaded" you@youremailid.com
      fi
    done
    Save this to a file named /root/monitor-uploads.sh
    Make it executable:
    Code:
    chmod +x /root/monitor-uploads.sh
    NOTE: This code is untested.

    Your cronjob could be stored as the following file:
    Code:
    /etc/cron.d/uploads
    and could contain:
    Code:
    */1 * * * * root /root/monitor-uploads.sh > /tmp/monitor-uploads.log 2>&1

  3. #3
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    atreyu, your script will work of course.
    But may I suggest the use of inotify for this?

    e.g. incrond can watch the directoy for changes and trigger actions.
    You must always face the curtain with a bow.

  4. #4
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    That of course is a brilliant suggestion...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...