wendy

inotify based node watcher
git clone git://git.2f30.org/wendy.git
Log | Files | Refs | README | LICENSE

README (4617B)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  ╻ ╻┏━╸┏┓╻╺┳┓╻ ╻
  ┃╻┃┣╸ ┃┗┫ ┃┃┗┳┛
  ┗┻┛┗━╸╹ ╹╺┻┛ ╹
                -- by z3bra
===========================

(W)atch (EN)tire (D)irector(Y) is an inotify-based directory watcher.

With wendy, you can watch event in directories or files, and launch a
specific command when an event occurs.

The program is made the more simple possible, to leave the room to unlimited
uses. Be creative !

Every event raised by inotify is handled. Just sum them up to watch multiple
event at the same time. Here is the full table:
(see inotify(1) for a better explanation of those events)

    IN_ACCESS ........ 1
    IN_MODIFY ........ 2
    IN_ATTRIB ........ 4
    IN_CLOSE_WRITE ... 8
    IN_CLOSE_NOWRITE . 16
    IN_OPEN .......... 32
    IN_MOVED_FROM .... 64
    IN_MOVED_TO ...... 128
    IN_CREATE ........ 256
    IN_DELETE ........ 512
    IN_DELETE_SELF ... 1024
    IN_MOVE_SELF ..... 2048

To watch for both creation AND deletion in a directory, do some math:

    256 + 512 = 768

then, pass that value to wendy so that she can watch after both of them (did I
just say 'she'?).

You can also note that you can specify file/directory names either using the
-f flag, or from stdin (in this case, the -f flag must be omited).
As a hidden feature, the watch mask is changed everytime the -m flag is
provided, and the inotify watches are set everytime the -f flag is given. So
you can wathc different mask on different file using the same command, and
that's pretty cool!

Here are some examples:

    # Tell me whenever I have a new mail
    wendy -m 256 -d ~/mails/INBOX/new -t 60 -e espeak "You got a new mail"

    # On-the-fly recompilation
    wendy -l | grep -i close_write
    IN_CLOSE_WRITE ... 8
    find -name "*.c" | wendy -m 8 -q -d ~/src/dev/program/ -t 1 -e make


    # Get up to date with community based projects
    wendy -m 770 -f /mnt/nfs/project/ -t 30 -e popup 'project updated'

    # watch creation in the directory, and modifications on a file
    wendy -m 256 -f ./my_dir -m 8 -f file.txt -e echo awesome!

FAQ
===

> Can it work on a folder and sub folders ?

It does not. inotify does not handle this by default, and implementing this
would make the code grow in complexity to a level I don't want to reach.
But you could do something like:

    $ tree
    .
    ├── a
    ├── b
    │   ├── c
    │   └── d
    └── e

    5 directories, 0 files

    $ find a -type d | wendy -m 256 -v | cut -f2

That will add a watch to each directory, and output the names of the file
created (eg: "a/b/newfile").

---

> Can you explain why this exists? Doesn't inotifywait (from inotify-tools) do
> this exact same thing?

When I first started wendy, I was not aware of inotifywait. It was just a good
programming exercise.

With the time, I found wendy more and more useful, and added a few options to
make it faster and more 'generic' (It was first created to watch my mail
directory, to alert me of new mails).

Today, I know that inotifywait can be used for everything wendy does Anyway, I
still prefer using wendy because of this:

    * inotifywait exits upon event reception [1]
    * inotifywait does not allow to launch a command on event reception [2]
    * inotifywait with multiple events can end in an infinite line [3]
    * inotifywait cna't read names from stdin
    * inotifywait only handle the file modification event (eg, wendy can use
      the IN_ONLYDIR mask)
    * inotifywait exits right when an event occur, wendy can treat all queued
      events at a specific period
    * inotify-tools : 164kb against 12kb for wendy (ok, not that relevant)
    * I like the name 'wendy' better

[1] I'm aware of the '--monitor' flag, but the only way to exec a command with
this is a pain that implies read, a while loop and so on.

[2] In fact, you can, by doing "inotifywait -e <event> && command", and
wrapping it in a while loop. Well, don't forget to add a test to see if your
file still exists, to avoid infinite buggy loops. You'll end up with something
like:

    while test -e ~/path/to/my/file; do
        inotifywait -e <event> ~/path/to/my/file && command
    done

Good luck with this, I prefer "wendy -m <mask> -e command"

[3] one flag per event. events written in words:

    inotifywait -e access -e create -e delete -e modify -e attrib /path/to/file

I prefer

        wendy -m 774 -f ~/path/to/my/file

---

> Would you prefer to fight one horse sized duck, or 10 duck sized horses ?

Regarding size and number, I'd rather fight horses. Ducks are silly creatures.