LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-16-2014, 05:26 PM   #1
petemac117
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:

Code:
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, 01:10 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Maybe I'm overthinking this but if you use
Code:
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.
 
  


Reply

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


All times are GMT -5. The time now is 06:39 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration