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

Z55
  • 85
  • 5
  • http://stackoverflow.com/questions/16807876/shell-script-execution-check-if-it-is-already-running-or-not http://stackoverflow.com/questions/927091/how-to-check-in-a-bash-script-if-something-is-running-and-exit-if-it-is – MustafaP Feb 17 '14 at 09:24
  • look these two questions. I thinks yours is same with these – MustafaP Feb 17 '14 at 09:25
  • Thank. It is not for me right solution. Control must be from that file /root/data/myscript – Z55 Feb 17 '14 at 09:27
  • Do you want a generic solution or something that can work for `myscript`? – anubhava Feb 17 '14 at 12:24

2 Answers2

0

This should work.

if [[ "$(pgrep myscript)" ]]
then echo "This script is already running!"
fi
Hema
  • 167
  • 4
  • 15
  • It is wrong :-( Condition will be satisfied Whenever. Controls the startup of the same file... – Z55 Feb 17 '14 at 10:19
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.

Chandru
  • 1,306
  • 13
  • 21