How to secure only one running instance of Linux script?
-
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?
-
Hi,
No need for anyone. Just one will and you'll be fine.
What about this one : shell script run one instance ;) -
I ended up with something like this:
if [ `pgrep script.sh | wc -l` -gt 1 ]; then exit fi
Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.