[SOLVED] check directory for new files and send email alert
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.