nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Ubuntu Linux File Upload / Creation Email Notification

This is a discussion on Ubuntu Linux File Upload / Creation Email Notification within the Ubuntu / Debian forums, part of the Linux Distribution category; Good afternoon. I recently set up an SFTP server on one of our servers, and I have two issues I ...


Go Back   nixCraft Linux Forum > Linux Distribution > Ubuntu / Debian

Linux answers from nixCraft.


Ubuntu / Debian Discussion about Debian or Ubuntu Linux related problems.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 17-06-2009, 02:21 AM
Junior Member
User
 
Join Date: Jun 2009
Location: Phoenix, AZ
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cristobalaz is on a distinguished road
Default Ubuntu Linux File Upload / Creation Email Notification

Good afternoon.

I recently set up an SFTP server on one of our servers, and I have two issues I wanted to get resolved and I can't figure out an easy way to do it.

1. I would like an automatic email to be generated and sent to the user that uploaded a file to the FTP server. For example, it would state that <name of file> has been received at <time> on <date>.

2. I would also like an email generated and sent to an internal email group about any file that is uploaded to the server. For example, it would show: A new <file name> file has been uploaded in <folder name> on <date> at <server time>.

If anyone knows of a way to accomplish this, and could possibly help me out in a walk through of getting this set up, I would really appreciate it.

Thank you.
Reply With Quote
  #2 (permalink)  
Old 17-06-2009, 03:01 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

How do you upload file? Do you use a script to upload file or it is done by someone else by typing commands or sftp client?

If it is a script, the same script can send an email update.

If it is a manual method, you can use something called file FAM. It can monitors files and directories, notifying changes including new files. You need to install dnotify program using apt-get command:
Code:
apt-get install dnotify
Print change to the terminal every time a file created in /tmp
Code:
dnotify -C /tmp -e echo "File Created"
Execute the script called foo every time a file in /var/pub/ftp is created or deleted:
Code:
dnotify -CD /var/pub/ftp -e /path/to/script
Where /path/to/script can be as follows:
PHP Code:
#!/bin/bash
echo "File Uploaded at Server" | /bin/mail -'File Uploaded' you@example.com 
Above is pretty simple example, you need to install the following programs to write a good shell script:
  1. gamin - File and directory monitoring system
  2. incron - cron-like daemon which handles filesystem events
  3. inotail - tail replacement using inotify
  4. inoticoming - trigger actions when files hit an incoming directory
  5. inotify-tools - command-line programs providing a simple interface to inotify
  6. iwatch - realtime filesystem monitoring program using inotify
Install the above program and read the man pages. If you need any more help just hit reply button.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
raj (17-06-2009)
  #3 (permalink)  
Old 17-06-2009, 04:09 AM
Junior Member
User
 
Join Date: Jun 2009
Location: Phoenix, AZ
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cristobalaz is on a distinguished road
Default

out of curiosity, any reason for using dnotify versus inotify?
Reply With Quote
  #4 (permalink)  
Old 17-06-2009, 04:44 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

dnotify is user land tool and do not requires to write code in C / C++ or other supported API. This is perfect for a shell script.

inotify provide the inotify API provides a mechanism for monitoring file system events. If you are willing to write code in Python, C, C++ go with this.

If performance is concern select inotify as it is ten time faster than dnotify.

HTH
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 17-06-2009, 05:08 AM
Junior Member
User
 
Join Date: Jun 2009
Location: Phoenix, AZ
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cristobalaz is on a distinguished road
Default

When I go to put in the first piece of code
Code:
dnotify -C /var/ftp -e echo "File Created"
it just sits there after pressing enter. I let it sit for about 5 minutes, and it seems to be just hanging.

I installed all of the suggested packages from your post, so is there possibly something I am doing wrong?
Reply With Quote
  #6 (permalink)  
Old 17-06-2009, 05:10 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Did any one upload a file in /var/ftp ? For testing try:
PHP Code:
echo "This is a test" > /var/ftp/tmp.txt 
You should see a message on screen.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #7 (permalink)  
Old 17-06-2009, 05:14 AM
Junior Member
User
 
Join Date: Jun 2009
Location: Phoenix, AZ
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cristobalaz is on a distinguished road
Default

What I mean is that when I did the following
Code:
# dnotify -C /tmp -e echo "File Created"
I hit enter, and it goes down to the next line and is blank...just sits there and does not go back to the command line.
Reply With Quote
  #8 (permalink)  
Old 17-06-2009, 07:22 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

I think command is waiting for event. You may go into background:
Quote:
Run dnotify in the background - detach from terminal. Prior to executing any commands, dnotify will change the current directory to the root directory (‘/’). Relative path names of directories to monitor will be made absolute automaticly, but make sure the command you specify does not rely on the current directory being unchanged.
So it should be
Code:
dnotify -b -C /var/ftp -e echo "File Created"
or may be
Code:
dnotify -b -C /var/ftp -e logger "File Created"
To see update run tail -f over /var/log/messages
Code:
tail -f var/log/messages
From another terminal upload file using ftp or lftp client.
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #9 (permalink)  
Old 18-06-2009, 04:16 AM
Junior Member
User
 
Join Date: Jun 2009
Location: Phoenix, AZ
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
cristobalaz is on a distinguished road
Default

Thank you for your help, I was able to get this working using the dnotify in background mode. I actually wrote the following shell script to do this:

Code:
#!/bin/bash

echo "To:xxxx@xxxx.com" > /var/upload.txt
echo "From:xxxx@xxxx.com.com">>/var/upload.txt
echo "Subject:blah blah">>/var/upload.txt
echo "blah blah message">>/var/upload.txt
cat /var/upload.txt|/var/qmail/bin/qmail-inject
Now, can anyone tell me from that above shell script how I would get it to insert which directory the file was uploaded to? If possible, the time and date also?

Last edited by cristobalaz; 18-06-2009 at 05:10 AM.
Reply With Quote
  #10 (permalink)  
Old 18-06-2009, 06:34 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Use the string {} in the command specification is replaced by the name of the directory that was updated.
Code:
 dnotify -b -C /var/ftp -e /home/you/yourscript.sh {}
And /home/you/yourscript.sh

Code:
#!/bin/bash
DIR="$1"
echo "To:xxxx@xxxx.com" > /var/upload.txt
echo "From:xxxx@xxxx.com.com">>/var/upload.txt
echo "Subject:blah blah">>/var/upload.txt
echo "echo $DIR .... blah blah message">>/var/upload.txt
cat /var/upload.txt|/var/qmail/bin/qmail-inject
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
dnotify , fam , gamin , incron , iwatch , linux , watch file system changes


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux Shell Script to upload log files to Windows XP based FTP Server stefanuscyberia Shell scripting 6 18-11-2009 01:29 PM
Vsftpd control upload file size limits jaysunn CentOS / RHEL / Fedora 1 06-05-2009 11:29 PM
How to Delete a file on 46 th day from the day of creation knvpavan Shell scripting 6 12-02-2009 12:07 AM
Mail Notification Agent sumit Mail Servers 1 25-08-2007 08:05 PM
mysql account creation Linux software 1 28-01-2006 11:17 AM


All times are GMT +5.5. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38