Sunday, 6 April 2014

fsniper init script on Centos

Create a file name  "fsniper"  and add below content

[root@fsniper-1.3.1] vim /etc/init.d/fsniper


export HOME=/root

case "$1" in
start)
echo -n "Starting Fsniper: "
/usr/local/bin/fsniper --daemon
echo -e "... [ \e[00;32mOK\e[00m ]"
;;
stop)
echo -n "Shutdown Fsniper: "
kill -9 `ps aux | grep "fsniper --daemon" | grep -v grep | awk {'print $2'}`
echo -e "... [ \e[00;32mOK\e[00m ]"
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart"
exit 1
esac

exit 0

that's it, save and exit.

use below command to set execute permission for /etc/init.d/fsniper file

[root@fsniper-1.3.1] chmod +x /etc/init.d/fsniper


Start the fsniper service using below command

[root@fsniper-1.3.1] service fsniper start

or

[root@fsniper-1.3.1] /etc/init.d/fsniper start

After started the fsniper, we can check the fsniper process whether running or not

[root@fsniper-1.3.1] ps -aux | grep fsniper

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      2788  0.0  0.0  13588  1412 ?        S    Jul19   0:00 /usr/local/bin/fsniper --daemon
root     17060  0.0  0.0 103248   896 pts/2    S+   20:20   0:00 grep fsniper

[root@fsniper-1.3.1] 

Friday, 4 April 2014

How to install and Configure Fsniper on Centos


Fsniper is a useful tool for directory monitor, and execute predefined actions on files created or modified in that directory

Fsniper Installation


First we need to install require package for Fsniper

[root@manivel ~]# yum install file-libs file-devel pcre pcre-devel

Download Fsniper source blow link

[root@manivel ~]# wget http://projects.l3ib.org/fsniper/files/fsniper-1.3.1.tar.gz

[root@manivel ~]# tar xzf fsniper-1.3.1.tar.gz

[root@manivel ~] cd fsniper-1.3.1/

Compile and Install Fsniper  from source using below command

[root@fsniper-1.3.1] ./configure
[root@fsniper-1.3.1] make
[root@fsniper-1.3.1] make install

Fsniper Configuration


Open fsniper config file and change the path which directory need to monitor

[root@fsniper-1.3.1] vim /root/.config/fsniper/config


watch {
   # watch the "/test/django/test/media" directory for new files
   /test/django/test/media {
       recurse = true
       # matches any file ending with .php
       *.php {
           # remove files with extension .php
           handler = rm -f %%
       }
       *.html {
           # remove files with extension .html
           handler = rm -f %%
       }
       *.htm {
           # remove files with extension .htm
           handler = rm -f %%
       }
   }


Start Fsniper as Daemon using below command


[root@manivel ~]# fsniper --daemon

We can check the fsniper process id

[root@manivel ~]# pgrep fsniper
13080
[root@manivel ~]#