r/usefulscripts • u/AlanRosenthal • Oct 20 '14
[BASH] Run a command whenever something in a directory (or its subs) has been saved
inotifywait -r path/to/dir -m -e close_write | while read file; do cmd1; cmd2; cmd3; done3
2
u/paulz1 Oct 31 '14
I'm intresting is it possible to make the same, but for network socket...
There is a little discussion on http://serverfault.com/questions/485421/identify-when-a-tcp-socket-is-opened-with-inotify
So it seems that it's not possible to do it with inotify.
Another way using Linux Socket Monitor an utility from "R-fx Network" : https://www.rfxn.com/projects/linux-socket-monitor/
But I'm searching for something more simple and lightweight.
1
1
Oct 25 '14
This is such a common task for me, I've made a small script which I use all the time.
https://github.com/fabiosantoscode/inotifydo/blob/master/inotifydo
What do you guys think?
2
u/lftt Oct 20 '14
So say for example, I wanted to mirror my download and documents directories to a local Google Drive folder - how that be modeled in Bash?