views:

67

answers:

5

Hi All,

I want to store the file and file information into the database automatically, when any file is inserted into the directory.

Let suppose, in the /etc directory, we store some log files. And if we are inserted new file into /etc directory or change any existing file then automatically these file information should be go to specific database table.

How can i do that.

Regards, Amit

A: 

A current-working-directory is a feature of the current shell so you can modify the cd command in your shell by putting:

function cd() {
   builtin cd $@
   do_some_action $@
}

in your .bashrc or equivalent file.

Chen Levy
A: 

various elementary methods

  1. store the checksum of the files using md5sum/sha512sum command into a file/database. then check against the database everytime you run md5sum/sha512sum. this will check for duplicates or whether a file has changed its contents. Also compare file sizes if necessary
  2. use tools like diff to compare base files
  3. use find or tree to list directory structures and store to file. remember to sort them if needed. then compare using diff for every run.
  4. for other file information like modification time, access times, file permission, etc you can use stat command
ghostdog74
+1  A: 

You want to use inotify. inotify allows you to efficiently watch a directory to see when files are added or changed.

R Samuel Klatchko
+2  A: 

INOTIFY(7) Linux Programmer’s Manual INOTIFY(7)

NAME

inotify - monitoring file system events

DESCRIPTION

The inotify API provides a mechanism for monitoring file system events. Inotify can be used to monitor individual files, or to monitor directo‐ ries. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

Inotify is Linux-specific but in addition to its C API also has (at least) binding in Python as well. Since you don't specify what programming language you are using in Linux, I can't really help you further except recommend that you look for Inotify functions in your Linux programming environment of choice.

Teddy
thanks teddy, let me know how, where I write these think? For ur information I am new in linux. So please explain in detail. And second thing, using INOTIFY(), we can monitor file system but if there is any change in file then how can insert file information into database (basically how can I call db from linux). Because I know these thing in language like java. But in linux, I don't know.
Hi teddy, for your information I am using PHP. But I can use any other language for that if PHP is not support it. So what your suggestion.
A: 

Gamin would be another alternative. It also has Python bindings.

daddz