2

I have a directory that gets written to when other machines send files via FTP. I want to put something in place that notices when files arrive and if their file name contains a particular substring (like "jpg"), move the file to some other directory (only after the file has finished arriving, not before)

I want to put this in place on many different kinds of Linux boxes. One such box has Linux kernel 2.4.22. It is possible there are older ones. I'm still checking.

On the older machines, I see this: inotifywait: command not found.

I've also seen this: The inotify API is available in Linux 2.6.13 and later

And this: bash: watch: command not found

Ideas in POSIX sh or bash or C could work. Perl and Python are probably not available everywhere I want to run this. I don't have permission to install packages.

3
  • Why is inotifywait not available? Oct 8 '15 at 19:32
  • man watch should give you what you need.
    – Jenny D
    Oct 8 '15 at 19:35
  • The kernel is too old. No inotifywait and no watch Oct 9 '15 at 20:15
3

I wrote this Perl program a long time ago that could get you started if you understand it. It uses uses the inotify feature in the kernel.

http://www.win2ix.ca/2013/05/31/606/

You'll have to change the code from synchronization to doing whatever you need, but it's mostly all there.

I know you have a problem with Perl, but I wanted to give this to you just in case.

If it helps, here's a demo on how to do it with C

http://man7.org/tlpi/code/online/diff/inotify/demo_inotify.c.html

3
  • Yeah, that C demo looks pretty easy to modify Oct 8 '15 at 23:07
  • Ah. One of the older machines I have to run this on has Linux 2.4.22 and "the inotify API is available in Linux 2.6.13 and later" Oct 9 '15 at 19:55
  • 1
    I think you'll need to create a script or something to constantly look for changes then. Oct 12 '15 at 14:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.