Stick your file to a specific path with stickfile

2011-01-20 15:57:40 GMT

Update (2011-04-22): Zach let me know in the meantime that there's a much easier way to implement stickfile in BASH:

Moral of the story: I should have searched for inotify command line which would lead me to inotify-tools which contains inotifywait.

And now to the original post:

My employer uses SonicWALL NetExtender for his VPN needs. Saying that I'm not a fan of IPsec would be definitely an understatement, but my major problem is that NetExtender overwrites my resolv.conf upon every connection which screws the hostname resolution on my LAN from my laptop. chmoding or chowning resolv.conf doesn't help because it gets re-chowned and re-chmoded by NetExtender.

I was thinking about overwriting resolv.conf on a regular basis from a script but it seemed rather inelegant. But how should I do it otherwise? With inotify, of course.

Here's the script I've written which you should save as "stickfile" to a directory that is featured in your $PATH.

After I created a valid resolv.conf and saved it as /etc/resolv.conf.orig I only had to execute the following as root before starting up NetExtender:

stickfile /etc/resolv.conf.orig /etc/resolv.conf

Comment written by at 2011-01-20 16:01:11 GMT:

Nice! Why does your employer use sonicwall? The last time I used it was a piece of shit!

Comment written by Laci at 2011-01-20 16:19:00 GMT:

Anonymous: I'm not sure why they use NetExtender. Maybe there was some Cisco gear in the corner that they wanted to use. :)

Comment written by Zach at 2011-04-18 02:53:46 GMT:

Thanks -- this was really helpful (funny, same employer actually). One thing though, I had to modify the py script to use get_wd instead of keeping the global variable around. Was getting an error in remove_watch(), saying the descriptor was invalid.

def add_watch():
    global watch_manager, file_to_stick
    watches = watch_manager.add_watch(file_to_stick, IN_MODIFY | IN_DELETE_SELF)

def remove_watch():
    global watch_manager

Comment written by Laci at 2011-04-18 09:58:03 GMT:

Hey Zach,

Funny indeed, the world is so small. Thanks for your input. The above script works perfectly for me but I can imagine others using a different version of Python or pyinotify having issues with it and your fix might just come handy for them.