• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

How to secure only one running instance of Linux script?

Scheduled Pinned Locked Moved General pfSense Questions
3 Posts 2 Posters 273 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B
    Bamsefar
    last edited by Jan 10, 2018, 7:17 AM

    Hi,

    So I am trying to get one of my scripts in pfSense to only start once so to speak, just as a precaution. Normal mode would be it starts itself automatic, and well that's just enough. However I like to double check that it is not already running. So I though I code it like:

    running=$(ps aux | grep CheckIfHome.sh | grep -v grep | grep -o CheckIfHome.sh | wc -l);
    
    if [ $running > 1 ];
    then
      exit
    fi
    

    But this will fail with "invalid variable" and for some reason my head seems to be on vacation…? Anyone that might help out?

    1 Reply Last reply Reply Quote 0
    • G
      Gertjan
      last edited by Jan 10, 2018, 12:24 PM

      Hi,

      No need for anyone. Just one will and you'll be fine.
      What about this one : shell script run one instance  ;)

      No "help me" PM's please. Use the forum, the community will thank you.
      Edit : and where are the logs ??

      1 Reply Last reply Reply Quote 0
      • B
        Bamsefar
        last edited by Jan 11, 2018, 8:47 PM

        I ended up with something like this:

        
        if [ `pgrep script.sh | wc -l` -gt 1 ];
        then
          exit
        fi
        
        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          3/3
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
          This community forum collects and processes your personal information.
          consent.not_received