Linux - NewbieThis 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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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:
tail -f /var/log/transfer.log | while read INPUT
<greps and e-mail stuff>
*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.
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.