Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9233293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:31:09+00:00 2026-06-18T06:31:09+00:00

I am looking write a small bash script to, when launched, watch a directory

  • 0

I am looking write a small bash script to, when launched, watch a directory for any newly created files. If a new file appears, I want its presence to trigger a second script to run.

I see this being used to trigger the compression recently digitized video, and add it to a log of ingested footage.

Currently my code looks like this:

#!/bin/sh

##VIDSTAT is a global variable coming from a parent script.
##proj is the ingestion directory coming from a parent script
proj=$1

dir="/home/$USER/data/movies/$proj"
dirlist=$(ls $dir)


while { $VIDSTAT -eq 1 }:
do
    for mov in $dirlist
    do
        if [ "$(( $(date +"%s") - $(stat -c "%Y" $mov) ))" -lt "5" ]
        then
        ~/bin/compressNlog.sh $mov
        fi
    done
done

Is there an easier/cleaner/less memory intensive way to do this?

EDIT I will be changing the ingestion directory per capture session. I have adjusted the code accordingly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:31:10+00:00Added an answer on June 18, 2026 at 6:31 am

    How about incron? It triggering Commands On File/Directory Changes.

    sudo apt-get install incron
    

    Example:

    <path> <mask> <command>
    

    Where <path> can be a directory (meaning the directory and/or the files directly in that directory (not files in subdirectories of that directory!) are watched) or a file.

    <mask> can be one of the following:

    IN_ACCESS           File was accessed (read) (*)
    IN_ATTRIB           Metadata changed (permissions, timestamps, extended attributes, etc.) (*)
    IN_CLOSE_WRITE      File opened for writing was closed (*)
    IN_CLOSE_NOWRITE    File not opened for writing was closed (*)
    IN_CREATE           File/directory created in watched directory (*)
    IN_DELETE           File/directory deleted from watched directory (*)
    IN_DELETE_SELF      Watched file/directory was itself deleted
    IN_MODIFY           File was modified (*)
    IN_MOVE_SELF        Watched file/directory was itself moved
    IN_MOVED_FROM       File moved out of watched directory (*)
    IN_MOVED_TO         File moved into watched directory (*)
    IN_OPEN             File was opened (*)
    

    <command> is the command that should be run when the event occurs. The following wildards may be used inside the command specification:

    $$   dollar sign
    $@   watched filesystem path (see above)
    $#   event-related file name
    $%   event flags (textually)
    $&   event flags (numerically)
    

    If you watch a directory, then $@ holds the directory path and $# the file that triggered the event. If you watch a file, then $@ holds the complete path to the file and $# is empty.

    Working Example:

    $sudo echo spatel > /etc/incron.allow
    $sudo echo root > /etc/incron.allow
    

    Start Daemon:

    $sudo /etc/init.d/incrond start
    

    Edit incrontab file

    $incrontab -e
    /home/spatel IN_CLOSE_WRITE touch /tmp/incrontest-$#
    

    Test it

    $touch /home/spatel/alpha
    

    Result:

    $ls -l /tmp/*alpha*
    -rw-r--r-- 1 spatel spatel 0 Feb  4 12:32 /tmp/incrontest-alpha
    

    Notes: In Ubuntu you need to activate inotify at boot time. Please add following line in Grub menu.lst file:

    kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/sda1 ro inotify=yes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to write a Java program which will download a Java source file
I'm looking to write a simple proxy server in .NET. Does anyone have any
I'm looking to write a small web service to run on a small Linux
I'm looking to write a small program which will intercept network packets (on the
I'm looking to write a PHP script to act as a mini daemon to
I'm looking to write a small client-server-based text game that handles multiple client connections
I want to write a small reporting tool and looking to fetch data from
I am looking to write a small audio processing program, and I need some
I'm looking to write a small C compiler, and I can't seem to find
I am looking to write a small application that receives an SMS text message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.