I have problems executing a script in ksh with this script named
process.sh:
ps -ef | grep process.sh | grep -v grep | wc -l | read a
if [ $a -gt 1 ]
then
echo "The script is running"
exit 0
fi
The problem is that when I execute the script, sometimes it shows the
message "The script is running", when I think it's impossible.
The reason that I write "wc -l|read a" is that
the count returns 1 because the "ps" is executed in the same script.
My idea is that nobody execute 2 times the same script, only on time.
It is similar to the original script you posted, except that instead of piping the line count to "read", I just assign it directly to a variable -- this is a cleaner and more direct method of doing it. I also eliminated the
"grep -v grep" with a little shell trickery -- the [s]quare brackets on the first letter of the script name. Its a personal preference, but I like this method better.
Thanks for your reply, but I have tested your code and my code 100 times (with a "for" writing to a log) and your code has failed 74 times and my code 63.