Fsniper

1379

Fsniper is a tool to watch for files, and execute commands on them. It can be aquired by anyone running archlinux via these commands

 wget  http://aur.archlinux.org/packages/fsniper/fsniper/PKGBUILD

sudo makepkg -i

 

and that’s it. Installed. To start fsniper use the fsniper binary. This will start in the foreground by default, which negligates it’s use. Instead of executing it with a “&” appended, we just use the –daemon option. This executes it as, you guessed it, a daemon. Don’t execute it yet though, as we have no configuration file

Fsniper uses one configuration file, located in ~/.config/fsniper/config. It  has a very simple structure, but it is a bit littered with curley brackets, so be carefull. Here’s the layout:

  watch {

                Directory/you/want/to/watch {

                                 files {

                                       handler = comand you want to execute on file

                                  }

                  }

}

 

The files can be defined via name or mime type. The program takes wildcards (* and so on) aswell as enviroment variables. For the handler, “%%” is the full file path, while “%” is just the file name.

  As you can see, it’s a simple setup, but hugley usefull. Here is my configuration file:

 watch {

                $HOME/bin {

                                * {

                                               handler = chmod 755 %%

                                 }

                  }

                $HOME {

                                 Desktop {

                                                    handler = rmdir %%

                                 }

                 }

}

The first one makes every new file in my bin directory executable, and the second one deleats the Desktop folder everytime it is created (kde desktop keeps making one)

 

I can’t see much more to say about fsniper apart from one thing, DON’T use it on file types you are likly to download with firefox (*.tar.gz, *.zip, *. jpg ect, ect,) as they are first put into a *.*.part file, while a seperate *.* file is created, meaning that the *.* file is acted upon, but before it has had any data inputed into it from the *.*.part file.