0

I'm not an advanced user of Linux, but I'm looking for some simple script in bash which will be working in cron or any other way and in 5-10 minutes period time will be looking for new files, after new directory/files are already uploaded to the directory script will move new directory with files to other location.

I found inotify which can be a great solution for this, but the issue is how to go with it.

vxstorm
  • 173
  • 2
  • 15
itnoob
  • 13
  • 7
  • http://stackoverflow.com/questions/4062806/inotify-how-to-use-it-linux – riteshtch Mar 01 '16 at 08:56
  • But i think its not related answer for my question. I`m looking for solution which will move "new" files to new place. – itnoob Mar 01 '16 at 09:05
  • Use [incron](http://inotify.aiken.cz/?section=incron&page=about&lang=en). It's from the developers of inotify and made for that purpose. Anyway your question here is too broad. – hek2mgl Mar 01 '16 at 09:05

1 Answers1

-1

I've been using inotifywait to recognize that some filesystem change ocurred in certain path.

Take a look at: http://linux.die.net/man/1/inotifywait

You can specify on what changes you are interested (delete, create, modify, etc.) and whether the script should output it or simply exit after change.

I've been using this tool in a way that my script was starting inotifywait and when it exists, do some action and restart inotifywait again.

Hope this helps. Martin

  • I created something like this based on the many information in the internet but the pity is how to work with directory which contains some files. `cd "$dir"` `inotifywait -m -r -q -e close_write --format %f . | while IFS= read -r file;`do `mv -p "$file" "$target"` `echo "$file has been copied to the $target"` `done` – itnoob Mar 01 '16 at 10:36
  • Sorry, I don't understand - "how to work with directory which contains some files"? What do you mean? What's the problem? – martin.hanes Mar 01 '16 at 12:33
  • Ok again. I have some directory called for example "uploaded" I want to monitor this directory for some updates. From time to time this directory will contain files and directories and files in these directories. /uploaded/directory/file1.mpg /uploaded/directory/file2.txt /uploaded/directory2/file.avi /uploaded/directory3/file4.mpeg Then this files should be moved with his own structure to the new location after when all operation on file finished. /moved/directory/file1.mpg /moved/directory/file2.txt /moved/directory2/file.avi /moved/directory3/file4.mpeg – itnoob Mar 01 '16 at 12:55
  • To maintain file structure, how about use rsync for it? something like: while [ true ]; do inotifywait -m -r -q (other options) && rsync -ar /uploaded/ /moved/ ; done http://linux.die.net/man/1/rsync – martin.hanes Mar 01 '16 at 13:33