#!/bin/sh 
echo "this is not an actual script" ; exit 0
# This is NOT a complete script, but a sample method to ensure script does 
# not run twice at the same time.

LOCK=/tmp/LCK-`basename "$0"` 

if test -f $LOCK 
then 
echo "Already one instance is active and in running state. PID=`cat $LOCK`" 
exit 1 
else 
# store process ID in LOCK file 
# set up trap to remove LOCK file when script exits, killed, dies, etc 
echo $$ > $LOCK 
trap "rm -f $LOCK" 1 2 15 
fi 

# end of code
 
# Jim Wingbermuehle . Minoah, you can enhance your LOCK code by doing a 
# "kill -0 $PID" and checking the return. A "kill -0" will check if the 
# process exists, but will not kill it. So if the process exists you will 
# get a 0 return code. This will make sure your process does really still 
# exist, because if someone does a "kill -9" on your process, your trap 
# will not catch it.

# Another possibility
FLAG_FILE="/tmp/pid_Scriptname.txt" 
## you can put any name instead of Scriptname 
if [ -f "${FLAG_FILE}" ] 
then 
# Check if a process is running 

pid=`cat ${FLAG_FILE}` 
echo "pid $pid" 
output=`/usr/bin/ps -p "${pid}"` 

if [ $? = 0 ] 
echo "one instance PID: ${pid} is already running" 

exit 1 
fi 
fi 
# Put pid in the flag_file 
echo $$ > "${FLAG_FILE}" 
`sleep 2`
