Auto copy for files from folder to folder upon instant writing

Hello all,
I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written.

I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me scenario because the written files to /path/to/a/ gets deleted on random timing sometimes the file get written and deleted in less than 5 seconds sometimes its over a minute or hours.

is there a technique in unix that i'm unaware of that does this?

Platform is mostly Linux flavors such as redhat/centos/debian or FreeBSD

Thank you.
Bashar

Bad approach imho. Please tell us why you aren't using network filesystem or san concepts.
Otherwise man inotify for 2.6 kernels and man fcntl for 2.4 kernels searching for F_NOTIFY.

I'm trying to do something similar and have been reading posts and experimenting all day. On my team, we sometimes modify a file with vi but forget to stop and make a backup copy of the original first. You can imagine that "rollback" is almost impossible with this little "problem."

I'd like to do an automatic copy, date/time stamp automatically appended to the file name, and alias vi to call this automatic copy script as follows:

vi <file>
file is automatically copied to <file>.00814201440
make your changes
quit vi

If you worked out this problem or (anyone) came up with an answer or can, please let me know, thanks!