Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»Install Fsniper ( Directory Monitoring ) Tool in CentOS, RHEL and Fedora

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

    RahulBy 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.

    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
    Previous Article5 Wget Examples to Download Files on Linux Command Line
    Next Article xargs Command in Linux with Useful Examples

    Related Posts

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Enable SSH Server on Ubuntu 22.04

    Updated:April 22, 20222 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    10 Best Linux Video Players in 2022

    Updated:February 18, 20226 Mins Read

    How to Switch Python Version in Ubuntu & Debian

    Updated:April 22, 20223 Mins Read

    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

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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