Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-16-2014, 04:26 PM   #1
LQ Newbie
Registered: Feb 2014
Posts: 8

Rep: Reputation: Disabled
keeping track of directory being checked by "inotify -r"

Alright, here's the deal:

I'm writing a bash script that will monitor files being pushed to an FTP server using inotifywait. The idea is to ensure that new files are being pushed continuously (e.g. every 1-2 minutes). My idea is that I can do this by formatting the output of inotifywait to print the seconds since 1970 (to avoid parsing timestamps) and then just comparing that value with the previous file that was added. So far, I have to following command within a while loop:

inotifywait -r -q -e create --format '%T' --timefmt '%s' /home/pete/FTP;
This is working as expected and outputting a large int representing the seconds since 1970.

I want to store this value in a variable to be compared to the next file that is added. The problem is that, since the watch is recursive and monitoring multiple directories within /FTP, I don't know how to store a separate value for each sub-directory.

Essentially, I need a way to store a previousTime value for each sub-directory of /FTP. For example, if FTP contains directories 1, 2, and 3, each with files being added to them continuously, I will need to store the variables previousTime1, previousTime2, and previousTime3. However, these can't really be hard-coded in because the number of directories within /FTP needs to be able to change.

Is there a way for me to keep track of what directory the create event has occurred in (in addition to the timestamp)? Or some better way to do this?

Any suggestions would be great because I'm pretty stumped at this point. Thanks in advance!
Old 04-17-2014, 12:10 PM   #2
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
Maybe I'm overthinking this but if you use
inotifywait -mrq -e create --format '%T %w%f' --timefmt '%s' /some/directory
then you get epoch plus a name. You could then add a hash for name (say SHA256) and then pipe the output to a log file (or simply a sqlite3 database?). So when a new directory or file name comes along you only have to turn that into a hash, search back the hash and see if it matches your $(date +%s --date="120 seconds ago")? The reason for using a hash is that you don't trip over odd directory or file names (user input!) and since it's relatively unique it should be relatively quick to look up.


inotify, inotifywait

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
Getting access denied when "user must change password at next logon" is checked . tom345 Linux - Security 2 03-02-2011 05:12 AM
[SOLVED] Debian ppc install iso when checked says "invalid no of alocation blocks" gajbooks Linux - Software 3 02-06-2011 08:06 AM
Perl: how to save an e-mail attachment on disk keeping the "&" character (no "%26"!!) d1s4st3r Programming 5 09-29-2010 09:30 PM
bash history and keeping track of current working directory andrews-mark Linux - General 11 06-13-2010 07:24 AM
patching the kernel with "inotify" abhi_abhijith Linux - General 2 02-27-2006 10:50 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:15 PM.

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