Stick your file to a specific path with stickfile

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

4 Comments

  1. says:

    2011-1-20, Thursday at 17:19

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

  2. Zach says:

    2011-4-18, Monday at 03:53

    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
        watch_manager.rm_watch(watch_manager.get_wd(file_to_stick)) 
    
  3. says:

    2011-4-18, Monday at 10:58

    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.

Leave a Reply

Your email address will not be published.