LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-08-2009, 02:02 PM   #1
cristobalaz
LQ Newbie
 
Registered: Jul 2009
Location: Phoenix, AZ
Posts: 3

Rep: Reputation: 0
File Upload Notification


Hello.

I am currently running Debian, and I have a an ftp server running on one of my servers with several accounts connecting to it.

I have two things that I need to accomplish, and a friend of mine said they would probably be best handled by a cron job. However, I am not very familiar with setting up a cron job, or how to do it in this case.

1. I need a notification to be sent to my email address every time a new file is uploaded to /var/ftp/. This would only be new files, and would not repeat the notifications unless that file was uploaded again. The subject line would show the date and name of the file uploaded, along with that being in the body of the email.

2. For one specific account, I would like a notification sent to a user outside my company. The subject line would have to contain the date and name of the file.

I currently run qmail, so hopefully that helps in the email notifications.

I really hope someone can help me, as I have been searching all over the web looking for an answer or walk through on accomplishing something like this. Thank you.
 
Old 07-08-2009, 02:13 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi,

And welcome to LQ!

Let's see. The cron part is easy - you just need to decide how
frequently you want those checks to appear/what interval you need
the notifications in.

The hard(er) part will be scripting the logic that decides whether
to mail something, and who to mail it to.

Basically the script you'll be invoking from cron needs to take a
status of your ftp directory, store that somewhere, compare it to
the previous run, and send mail if there's a difference.



Cheers,
Tink
 
Old 07-08-2009, 02:22 PM   #3
cristobalaz
LQ Newbie
 
Registered: Jul 2009
Location: Phoenix, AZ
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the welcome Tinkster.

I would like the cron job to run either constantly (instant notification), or if that might be too intensive, maybe every 4-5 minutes?

I am not knowledgeable at all in scripting, so if anyone is willing to help out, that would be great.

Thank you.
 
Old 07-08-2009, 02:37 PM   #4
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
Before trying to figure out the logic, you might want to look to see if your ftp server has a transfer log capability. proftpd does. The idea that you log whenever a file is uploaded to a certain directory would just be to grep the transfer log for that directory. All logs (at least in proftpd) are logged with the path, file, and account, so finding that one account you need would be easy also.

If you want instant notification, you can use a "tail -f" on the log file and read that into your loop in the script. You would not need cron at all. The script would halt running waiting on input from the tail command. The loop would look like:
Code:
tail -f /var/log/transfer.log | while read INPUT
do
    <greps and e-mail stuff>
done
*There's probably a better way to write that.

As for e-mail, check out mailx. It's a very scriptable cli program for e-mail.

Last edited by nuwen52; 07-08-2009 at 02:53 PM.
 
Old 07-08-2009, 04:47 PM   #5
cristobalaz
LQ Newbie
 
Registered: Jul 2009
Location: Phoenix, AZ
Posts: 3

Original Poster
Rep: Reputation: 0
I would much more prefer a cron method. Anyone out there able to help me with the scripting needed to do this?
 
Old 07-08-2009, 08:05 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
For instant notification, post #4 should work.

If you don't need that (and you probably don't), then a cron job every eg 5 mins should suffice.
It really depends how often you expect uploads and how soon you want notification.
This is a key design issue.

cron has 1 minute resolution, but starting a new process over and over again is not a good idea.

You would need to somehow track txfr log status so you can tell when a new file was logged.
If the ftp log allows date/timestamps in the log ie for each record, the record the last timestamp seen and go from there.
Otherwise, just count the num of lines in the file and go from there.
In either case you need to save the last timestamp/linecount in a temp file.

If you wrote your own daemon instead, you'd just store last time/recnum in mem and loop every say 5 mins.

Good scripting links:

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

cron doc: http://www.adminschoice.com/docs/cro...Crontab%20file
 
Old 07-08-2009, 09:08 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by cristobalaz View Post
Thanks for the welcome Tinkster.

I would like the cron job to run either constantly (instant notification), or if that might be too intensive, maybe every 4-5 minutes?

I am not knowledgeable at all in scripting, so if anyone is willing to help out, that would be great.

Thank you.
There's no such thing as "constantly" with cron. It's finest
granularity is 1 minute.

As for the script ... that'll take some time :}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload file to ftp server -vsftp- but can not delete or change the file once uploaded murattas6 Linux - Server 2 06-26-2009 07:00 AM
notification-daemon temporary file location? eleifsp Linux - Software 1 01-27-2009 01:33 AM
Automated FTP Notification when file uploaded by user c955437 Linux - Server 1 07-09-2007 10:08 AM
web server (fedora core 5) became read-only file system after i upload a file nggs8411 Linux - Server 1 03-26-2007 10:23 AM
Samba V3 - File Change Notification not working David_Campen Linux - Networking 0 10-24-2006 12:03 PM


All times are GMT -5. The time now is 06:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration