2

I have a script /root/data/myscript

and when I run /root/data/myscript

I do not know how to determine if you have one running

does anyone know?

I tried

if [[ "$(pidof -x /root/data/myscript | wc -w)" > "1" ]]
then echo "This script is already running!"
fi

thank you

4
  • stackoverflow.com/questions/16807876/… stackoverflow.com/questions/927091/… Commented Feb 17, 2014 at 9:24
  • look these two questions. I thinks yours is same with these Commented Feb 17, 2014 at 9:25
  • Thank. It is not for me right solution. Control must be from that file /root/data/myscript Commented Feb 17, 2014 at 9:27
  • Do you want a generic solution or something that can work for myscript? Commented Feb 17, 2014 at 12:24

2 Answers 2

0

This should work.

if [[ "$(pgrep myscript)" ]]
then echo "This script is already running!"
fi
Sign up to request clarification or add additional context in comments.

1 Comment

It is wrong :-( Condition will be satisfied Whenever. Controls the startup of the same file...
0

This could work to check whether the script is already running or not.

if [[ "$(ps -ef | grep "/root/data/myscript" | grep -v "grep")" ]] ; then 
echo "This script is already running!"
fi

Try this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.