tunder-wendys-dress.txt - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
tunder-wendys-dress.txt (2875B)
---
1 # Under Wendy's dress
2
3 --- 31 March, 2015
4
5 I've been meaning to write this post for a long time.
6
7 ## who's that chick?
8
9 [`wendy`](http://git.z3bra.org/wendy/log.html) is an inotify based directory and
10 file watch. It is by far the project I'm the most proud of.
11 Back in the days, I discovered this awesome feature in the kernel: `inotify`.
12 It's a feature that will make the kernel raise events whenever a file or
13 directory (let's call them "nodes") will change.
14 It could be the creation, deletion, move, open, close of this node, and even
15 more.
16
17 After seeing there was a C library to interface with the inotify watch/events, I
18 immediately started writing a small program that would do one simple thing:
19 notify me when I received an email, and I named my creation **wendy**.
20
21 At first, all it did was the following:
22
23 $ wendy ~/var/mail/INBOX/new -e beep
24 watching directory ~/var/mail/INBOX/new
25
26 And my motherboard's speaker would beep everytime a new file was created in the
27 specified directory.
28
29 Now that it was working, I finally decided to make it more and more general, and
30 it finally reached its current state: a _general purpose node watcher_.
31
32
33 ## how does it work?
34
35 wendy -m 768 -f $HOME/directory -e popup "~/directory content updated"
36
37 The above command will create a popup each time a file is created or deleted in
38 `~/directory`.
39
40 `wendy` takes node names, masks, and an optionnal command, mix it up and will
41 then watch them up with the specified mask, and launch a command upon each event
42 triggered.
43
44 Wendy can also read filenames from stdin, to add to its awesomeness ;)
45
46
47 ## play with her!
48
49 Get a popup when you receive a new e-mail
50
51 wendy -m 256 -f ~/var/mail/inbox/new -e popup "you have a new mail"
52
53 Automatically recompile a C project whenever a source file is changed
54
55 find -name "*.c" | wendy -m 8 -e make
56
57 Send an email to your admin whenever your webserver get an error
58
59 wendy -m 8 -f /var/log/httpd/error.log -e sh -c 'tail /var/log/httpd/error.log | mail -s "[ERROR] httpd on $(hostname)" sysadmin@domain.tld'
60
61 Make an "upload directory" on your system, using ssh and a passphrase-less private key
62
63 wendy -v -m 264 -f ~/var/uploads | while read mask file; {
64 extension=$(echo $file | sed 's/^.*\.\?//')
65 newname=$(tr -cd '[a-z0-9]' < /dev/urandom | fold -w 8i | sed 1q).${extension:-txt}
66 scp -i ~/.ssh/id_rsa $file user@domain.tld:/var/www/http/downloads/$newname
67 }
68
69 View manpages on the fly, as you write them
70
71 PAGER=cat wendy -m 8 -f wendy.1 -e sh -c "clear; man ./wendy.1"
72
73
74 the only limit.. Wait, there is no limit! Just let it go (I know you hate me for
75 saying that...)
76
77 ## contribution
78
79 If you find any bug, or weird behavior, or anything else, do not hesitate to
80 drop me an [email](mailto:contact@z3bra.org), or submit it on the
81 [mailing list](mailto:dev@z3bra.org).
82
83 Keep tweaking !