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 ...
- 09-27-2011 #1Just 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.
- 09-28-2011 #2Linux 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:
Save this to a file named /root/monitor-uploads.shCode:#!/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
Make it executable:
NOTE: This code is untested.Code:chmod +x /root/monitor-uploads.sh
Your cronjob could be stored as the following file:
and could contain:Code:/etc/cron.d/uploads
Code:*/1 * * * * root /root/monitor-uploads.sh > /tmp/monitor-uploads.log 2>&1
- 09-28-2011 #3
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.
- 09-28-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
That of course is a brilliant suggestion...


Reply With Quote