z3bra, the stripes apart

Under Wendy's dress

--- 31 March, 2015

I've been meaning to write this post for a long time.

who's that chick?

wendy is an inotify based directory and file watch. It is by far the project I'm the most proud of.
Back in the days, I discovered this awesome feature in the kernel: inotify. It's a feature that will make the kernel raise events whenever a file or directory (let's call them "nodes") will change.
It could be the creation, deletion, move, open, close of this node, and even more.

After seeing there was a C library to interface with the inotify watch/events, I immediately started writing a small program that would do one simple thing: notify me when I received an email, and I named my creation wendy.

At first, all it did was the following:

$ wendy ~/var/mail/INBOX/new -e beep
watching directory ~/var/mail/INBOX/new

And my motherboard's speaker would beep everytime a new file was created in the specified directory.

Now that it was working, I finally decided to make it more and more general, and it finally reached its current state: a general purpose node watcher.

how does it work?

wendy -m 768 -f $HOME/directory -e popup "~/directory content updated"

The above command will create a popup each time a file is created or deleted in ~/directory.

wendy takes node names, masks, and an optionnal command, mix it up and will then watch them up with the specified mask, and launch a command upon each event triggered.

Wendy can also read filenames from stdin, to add to its awesomeness ;)

play with her!

Get a popup when you receive a new e-mail

wendy -m 256 -f ~/var/mail/inbox/new -e popup "you have a new mail"

Automatically recompile a C project whenever a source file is changed

find -name "*.c" | wendy -m 8 -e make

Send an email to your admin whenever your webserver get an error

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'

Make an "upload directory" on your system, using ssh and a passphrase-less private key

wendy -v -m 264 -f ~/var/uploads | while read mask file; {
    extension=$(echo $file | sed 's/^.*\.\?//')
    newname=$(tr -cd '[a-z0-9]' < /dev/urandom | fold -w 8i | sed 1q).${extension:-txt}
    scp -i ~/.ssh/id_rsa $file user@domain.tld:/var/www/http/downloads/$newname

View manpages on the fly, as you write them

PAGER=cat wendy -m 8 -f wendy.1 -e sh -c "clear; man ./wendy.1"

the only limit.. Wait, there is no limit! Just let it go (I know you hate me for saying that...)


If you find any bug, or weird behavior, or anything else, do not hesitate to drop me an email, or submit it on the mailing list.

Keep tweaking !