|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Hi all, new to this found this script and i am trying to get it to work with our sytem. All I want is an email when the ftp directory changes. I dont need to know the file name(but would be nice). I have tried the script with sleeptime because it should loop but it doesnt work. I have tried with crond setting up for every 5 minutes, but all it does is give me an email every 5 minutes.
Email part works just removed my settings. Any help would be appreciated. Here is code I used with crond #!/usr/bin/perl my $dir = "/home/www/ftp"; my $sendto = "someone@somewhere.com"; my $sendfrom = "someone@somewhere.com"; my $sendsubject = "you have ftp!"; my $sendmessage = "it works"; my $mail = "/usr/sbin/sendmail"; #### you shouldn't need to change anything below here my @lastfiles; my $sendmail = "no"; while ( -e "$dir" ) { opendir(DIR,$dir); my @files = readdir(DIR); closedir(DIR); foreach(@files) { if ( ! grep(/$_/,@lastfiles) ) { $sendmail = "yes"; ## didn't see this file last ## time, so send email push(@lastfiles,$_); ## add this filename so we ## don't send mail over it next time } } if ( $sendmail eq "yes" ) { open(SENDMAIL, "| /usr/sbin/sendmail -t") || die "Unable to open sendmail"; print SENDMAIL "From: someone\@somewhere.com\r\n"; print SENDMAIL "To: someone\@somewhere.com\r\n"; print SENDMAIL "Reply-To: someone\@somewhere.com\r\n"; print SENDMAIL "Subject: You Have a new ftp file\r\n"; print SENDMAIL " Please Check ftp site\r\n"; close(SENDMAIL); } $sendmail = "no"; } |
|
#2
|
||||
|
||||
|
As it has been pointed out in a different thread this week, it's preferable to use cron rather than having a process constantly running.
I would suggest running a script every 5 minutes that checks all the files in your directory to see if they've been modified in the last 5 minutes (see the stat function) , sending you an email with details if any have. The reason running your script under cron every 5 mins sends you an email anyway is because initially, @lastfiles is empty, so if it finds anything at all, it'll send the mail. That script could cause memory problems if you leave it running. It keeps adding to @lastfiles as it finds new files. Over time, this array will get bigger and bigger, causing problems eventually unless you stop and restart the process, at which time it will pick up all the files in your dir as being new. The other prob with it is that if somebody uploads a newer version of an existing file (with the same filename), the script won't catch that because it already has that filename in @lastfiles.
__________________
~ishnid; Have you tried: [ search.cpan.org | perldoc | Java API | mysql.com | google ] Apostrophes are NOT used for possessive pronouns or for noun plurals, including acronyms. |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > watch ftp directory email when new file arrives |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|