Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monitoring for changes in file(s) in real time

I have a program that monitors certain files for change. As soon as the file gets updated, the file is processed. So far I've come up with this general approach of handing "real time analysis" in R. I was hoping you guys have other approaches. Maybe we can discuss their advantages/disadvantages.

monitor <- TRUE
start.state <- file.info$mtime # modification time of the file when initiating

while(monitor) {
  change.state <- file.info$mtime
  if(start.state < change.state) {
    #process
  } else {
    print("Nothing new.")
  }
  Sys.sleep(sleep.time)
}
like image 400
Roman Luštrik Avatar asked Jan 24 '11 09:01

Roman Luštrik


People also ask

How can you check in real time for changes made to a file?

- Go to: Settings → Preferences → MISC. → and here in the section "File Status Auto-Detection", make sure to select all three checkboxes ([✓] Enable, [✓] Update silently, [✓] Scroll to the last line after update). ...and you will see the file being updated in real time, as new log entries are written to it!

What is file activity monitoring?

File Activity Monitoring discovers the sensitive data on your servers; classifies content using pre-defined or user defined definitions; configures rules and policies about data access, and actions to be taken when rules are met.

How do I monitor the file and folder changes in Windows?

Login to ADAudit Plus → Go to File Audit tab → Under File Audit Reports → navigate to All File/Folder Changes report. Select the time period for which you want to track the changes made and the domain that the file server belongs to. The details you will find in this report are: Name of the file/folder that was changed.


1 Answers

Similar to the suggestion to use a system API, this can be also done using qtbase which will be a cross-platform means from within R:

dir_to_watch <- "/tmp"

library(qtbase)
fsw <- Qt$QFileSystemWatcher()
fsw$addPath(dir_to_watch)

id <- qconnect(fsw, "directoryChanged", function(path) {
  message(sprintf("directory %s has changed", path))
})

cat("abc", file="/tmp/deleteme.txt")
like image 167
jverzani Avatar answered Sep 17 '22 17:09

jverzani