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 fiBut 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginPrivacy Policy · Cookie Policy