Create a LOCK file using "echo $$ > $LOCK", so that you can get the process id of the script.
when you enter the script, check if the LOCK file exists, if yes then cat the file and do a ps -ef for that process id. If process is running, just exit. Else create the lock. Once the script completes, remove the lock. If lock file does not already exist when starting, create it and continue. Something like this :-
LOCK=/xyz/file.lck
if [ -f $LOCK ]; then
PID=`cat $LOCK`
PROC=`ps -ef | grep $PID | grep -v grep`
if [ " $PROC" = " " ]; then
echo $$ > $LOCK
else
exit 0
fi
else
echo $$ > $LOCK
fi
Instead of using PID, you can just touch a lock and remove it....but the problem occurs if the script starts, touches a lock and abruptly terminates....all further invoke of the script think that it is already running and exit..