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 8575673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:44:51+00:00 2026-06-11T19:44:51+00:00

I need some help. I’m having a script ‘Script 1’, which will call ‘Script

  • 0

I need some help. I’m having a script ‘Script 1’, which will call ‘Script 2’ to run in background which checks something periodically. But I want the Script 2 to get started only once, even Script 1 is called multiple times. Is there a way to do it?

It would be even more helpful, if someone suggests some commands to achieve this.

Thanks in advance

  • 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-11T19:44:52+00:00Added an answer on June 11, 2026 at 7:44 pm

    Sure, you can put something like this at the top of Script2:

    if [[ -f /tmp/Script2HasRun ]] ; then
        exit
    fi
    touch /tmp/Script2HasRun
    

    That will stop Script2 from ever running again by using a sentinel file, unless the file is deleted of course, and it probably will be at some point since it’s in /tmp.

    So you probably want to put it somewhere else where it can be better protected.

    If you don’t want to stop it from ever running again, you need some mechanism to delete the sentinel file.

    For example, if your intent is to only have one copy running at a time:

    if [[ -f /tmp/Script2IsRunning ]] ; then
        exit
    fi
    touch /tmp/Script2IsRunning
    # Do whatever you have to do.
    rm -f /tmp/Script2IsRunning
    

    And keep in mind there’s a race condition in there that could result in two copies running. There are ways to mitigate that as well by using the content as well as the existence, something like:

    if [[ -f /tmp/Script2IsRunning ]] ; then
        exit
    fi
    echo $$ >/tmp/Script2IsRunning
    sleep 1
    if [[ "$(cat /tmp/Script2IsRunning 2>/dev/null)" != $$ ]] ; then
        exit
    fi
    # Do whatever you have to do.
    rm -f /tmp/Script2IsRunning
    

    There are more levels of protection beyond that but they become complex, and I usually find that suffices for most things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help in creating function which can create folders recursively with giving path:
I need some help. I have a div inside which there are some radio
I need some help with my jQuery script. I have a page that refreshes
i need some help with a shell script. I want to start a shell
Need some help designing a bash script for grepping IP addresses from auth.log and
I need some help from the shell-script gurus out there. I have a .txt
need some help with building a powershell script to help with some basic string
Need some help on this. I am clicking on a delete image which is
Need some help on a script I am doing... what I want to accomplish
need some help with a MYSQL call. In one of my tables, I have

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.