方法1,利用flock

flock -xn /tmp/ktsee.lock -c 'sh /root/ktsee.sh'

方法2,脚本实现

#!/bin/sh

# check lock exist

if [[ -f /tmp/ktsee.lock ]]

then

echo ktsee is running

exit 1

else

touch /tmp/ktsee.lock

fi

# ===Start shell script content===

echo 'Visit http://3sv.ktsee.com'

# ===End shell script content===

# remove the lock

rm -f /tmp/ktsee.lock