I created a script to verify if a scheduled process is already running and in that case I block the execution showing a message "script is already running". The problem is that I inserted these lines of code
scriptToVerify="send_xxxx.sh ${1} ${2}";
num_proc=`ps auxww | grep "$scriptToVerify" | grep -v $$ | grep -v grep | awk /./ | /usr/bin/wc -l`;
if [ $num_proc -gt 1 ];
then
sl_log "---------------------------Warning---------------------------"
sl_log "$scriptToVerify Already running"
exit 0;
fi
in a large number of scripts (every script is scheduled, sometimes at the same time). I have tried different solutions: using a flock instruction, using a lockfile, but everytime (even the instructions I wrote above) my code works for a few weeks and then starts to report a "script already running" also it isn't true.
Unfortunately I can't manage the scheduler, so how can I modify my script in order to verify if a process is actually running?