Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»Install Fsniper ( Directory Monitoring ) Tool in CentOS, RHEL and Fedora

    Install Fsniper ( Directory Monitoring ) Tool in CentOS, RHEL and Fedora

    By RahulMarch 31, 20133 Mins Read

    Fsniper is a useful tool for directory monitor, and execute predefined actions on files created or modified in that directory. For example, if we want to make a backup of each files created in your web upload folder or ftp directory, Using fsniper we can copy all files created in that folder to backup disk.

    Advertisement

    Fsniper uses inotify to watch for when a file is closed after being written to.

    Step 1: Install Required Packages

    First install the required packages for fsniper installation on your system.

    # yum install file-libs file-devel pcre pcre-devel
    

    Step 2: Download Fsniper Source

    Download the latest fsniper source code or use below command to download it. Also extract the archive file in /usr/src directory.

    # cd /usr/src/
    # wget http://projects.l3ib.org/fsniper/files/fsniper-1.3.1.tar.gz
    # tar xzf fsniper-1.3.1.tar.gz
    # cd fsniper-1.3.1
    

    Step 3: Install Fsniper

    After extracting archive complile source code using following commands.

    # ./configure
    # make
    # make install
    

    Step 4: Configure Fsniper

    Create fsniper configuration file as instruction’s below.

    # mkdir ~/.config/fsniper/
    # vim ~/.config/fsniper/config
    

    Add below content in configuration file, You may need to change it as per your requirements.

    watch {
        # watch the /var/www/upload directory for new files
        /var/www/upload {
    	# matches any mimetype beginning with image/ in /var/www/upload directory.
            image/* {
                handler = cp %% /backup/web/upload/image/
            }
    	# matches all file with .pdf extension in /var/www/upload directory.
            *.pdf {
                handler = cp /var/www/upload/%F /backup/web/upload/pdf/
            }
        }
    }
    

    Details about configuration file:

    handlers: The handler is used to specify a command to be executed on match found in specified folder. .

    handler = cp %% /backup/web/upload/image/
    

    %% : is replaced with matched file name with full path.
    %F : is replaced with file name only.

    Step 5: Start Fsniper as Daemon

    Fsniper can be started in daemon mode using following command. So the process will not terminate either you logged our from system.

    # fsniper --daemon
    

    Step 6: Fsniper init Script

    Init scripts are useful for starting application on system boot, so we don’t need to start them after restarting system. Create an file named /etc/init.d/fsniper and add below content.

    # 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;32mOKe[00m ]"
    ;;
    stop)
    echo -n "Shutdown Fsniper: "
    kill -9 `ps aux | grep "fsniper --daemon" | grep -v grep | awk {'print $2'}`
    echo -e "... [ e[00;32mOKe[00m ]"
    ;;
    restart)
    $0 stop
    sleep 1
    $0 start
    ;;
    *)
    echo "Usage: `basename $0` start|stop|restart"
    exit 1
    esac
    
    exit 0
    

    And set the execute permission on script to run.

    # chmod +x /etc/init.d/fsniper
    # service fsniper start
    

    Thank You for reading this article, I hope this article will help you to setup fsniper on Linux server.

    directory monitoring using fsniper fsniper fsniper on linux fsniper setup in linux how to install fsniper install fsniperon centos setup fsniper on centos
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    An Introduction to the “./configure” Command: Compiling Source Code in Linux

    Getting Started with Linux Command line: The Beginning

    Backing Up Your Linux System with Rsync: A Step-by-Step Guide

    View 1 Comment

    1 Comment

    1. ssp on June 14, 2013 2:41 am

      Does it monitor the directories recursively? If not , how to get it?

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.