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

  • Home
  • SEARCH
  • 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 3942860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:42:48+00:00 2026-05-20T00:42:48+00:00

does anyone know how to lock on a function in bash script? I wanted

  • 0

does anyone know how to lock on a function in bash script?
I wanted to do something like in java (like synchronize), ensuring that each file saved in monitored folder is on hold ever tries to use submit function.

an excerpt from my script:

(...)

ON_EVENT () { local date = $1 local time = $2 local file = $3 sleep 5 echo "$date $time New file created: $file" submit $file }

submit () { local file = $1 python avsubmit.py -f $file -v python dbmgr.py -a $file }

if [ ! -e "$FIFO" ]; then mkfifo "$FIFO" fi

inotifywait -m -e "$EVENTS" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f' "$DIR" > "$FIFO" & INOTIFY_PID=$!

trap "on_exit" 2 3 15

while read date time file do on_event $date $time $file & done < "$FIFO"

on_exit

I'm using inotify to monitor a folder when a new file is saved. For each file saved (received), submit to VirusTotal service (avsubmit.py) and TreathExpert (dbmgr.py).
Concurrent access would be ideal to avoid blocking every new file created in monitored folder, but lock submit function should be sufficient.

Thank you guys!

  • 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-05-20T00:42:49+00:00Added an answer on May 20, 2026 at 12:42 am

    Something like this should work:

    if (set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
       trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
       # Your code here
       rm -f "$lockfile"
       trap - INT TERM EXIT
    else
       echo "Failed to acquire $lockfile. Held by $(cat $lockfile)"
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a good Command Prompt replacement? I've tried bash/Cygwin, but that
Does anyone know a good Java lib that will hook into SVN so I
Does anyone know the function of the command vmware-vim-cmd vimsvc/connect (vimid). I thought that
Does anyone know of an existing ruby implementation of a read/write lock - http://en.wikipedia.org/wiki/Readers-writer_lock
Does anyone know of any existing packages or libraries that can be used to
Does anyone know of an implementation of a lock free hash table in C#?
Does anyone know any good chart api for a web application in java? This
Does anyone know of a php class or library that helps deal with dates
Possible Duplicate: How do I lock a file in Perl? Does anyone know how
Does anyone know of a flash projector 'project' or 'framework' that uses a new

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.