LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-11-2009, 09:49 PM   #1
saifkhan123
Member
 
Registered: Apr 2009
Distribution: Red Hat/CentOS
Posts: 108

Rep: Reputation: 19
check directory for new files and send email alert


well, the scenario is, i have CentOS 5.2 based server running openssh, which gives sftp service to the outside users(from internet), the users from some public ip-addresses uploads and download files from sftp-server directories. I want that whenever a user uploads a new file in certain directory of server, the server should send me an email alert, kindly suggest how this is possible, and if somebody has a shell script for that, it will be a great favor for me, Regards
 
Old 09-12-2009, 12:30 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by saifkhan123 View Post
well, the scenario is, i have CentOS 5.2 based server running openssh, which gives sftp service to the outside users(from internet), the users from some public ip-addresses uploads and download files from sftp-server directories. I want that whenever a user uploads a new file in certain directory of server, the server should send me an email alert, kindly suggest how this is possible, and if somebody has a shell script for that, it will be a great favor for me, Regards
Aren't you interested in writing your own script, so you can become a rich, famous programmer and kick supermodels out of your bed?

Here is an outline for you to follow while writing your own script:

1. You will need a record of the old state of each directory, so you can detect new files, or new dates on existing files.

2. On a schedule, get a directory listing of each target directory and compare it with the record you've retained. If a file appears or changes, send the e-mail alert.

3. The script will test the directory against the record, note differences, send an e-mail if required, and update the record.

Sounds pretty easy. Well, time to get started writing your own script.
 
Old 09-12-2009, 01:13 AM   #3
saifkhan123
Member
 
Registered: Apr 2009
Distribution: Red Hat/CentOS
Posts: 108

Original Poster
Rep: Reputation: 19
can you be more specific??

sorry for this but i am a newbie to shell environment....i will ask you the questions 1 by 1
Quote:
1. You will need a record of the old state of each directory, so you can detect new files, or new dates on existing files.
wht should i use for this purpose, i mean there is "stat" command available for this, also "find" can help if it is used with "-mtime", and should i store this info in a variable to compare it later???

Quote:
On a schedule, get a directory listing of each target directory and compare it with the record you've retained. If a file appears or changes, send the e-mail alert.
this means, i will run this script in cron, i only have to monitor 1 directory so listing is not needed i think???and do i have to use if-then-else structure for defining a condition "if changed then send email" or any other thing available for that?


thanks for the Response
 
Old 09-12-2009, 01:45 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by saifkhan123 View Post
sorry for this but i am a newbie to shell environment....i will ask you the questions 1 by 1

wht should i use for this purpose, i mean there is "stat" command available for this, also "find" can help if it is used with "-mtime", and should i store this info in a variable to compare it later???


this means, i will run this script in cron, i only have to monitor 1 directory so listing is not needed i think???and do i have to use if-then-else structure for defining a condition "if changed then send email" or any other thing available for that?


thanks for the Response
Why not just get a directory listing and break it down by field, to detect changes? An easy way to do this is to tell "ls" what information to return:

Code:
ls -la --time-style=+%s
This invocation of "ls" returns the number of seconds since the epoch instead of a date and time. This is easy to compare to a prior time, because it's a single large number -- no interpretation required.

Quote:
i only have to monitor 1 directory so listing is not needed i think???
No, you must keep a record of prior file names and times. This is the only way to avoid either missing file changes, or sending more than one e-mail for the same file.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
using cron to send files via email aditaa Linux - Server 5 04-21-2009 04:03 AM
Bash script to check if process is running and send email depam Linux - Newbie 2 04-08-2009 12:11 AM
LXer: Perl script to monitor disk space and send an email alert LXer Syndicated Linux News 1 02-23-2007 01:12 PM
Script to check IP address and send to an email kbrajesh Linux - Networking 4 02-08-2007 03:13 AM
how to check that the email server is being used by someone to send spam ? kkeith Linux - Newbie 2 09-07-2006 06:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:03 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
Open Source Consulting | Domain Registration