monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

under-wendys-dress.txt (2931B)


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