避免shell脚本重复运行,禁止开启多个进程
#!/bin/bash
RUNDIR=`dirname $0`
PIDFILE="${RUNDIR}/$0.pid"
if [ -s ${PIDFILE} ] ; then
SPID=`cat ${PIDFILE}`
if [ -e /proc/${SPID}/status ]; then
echo "script have running, not repeat run , exit."
exit 1
fi
cat /dev/null > ${PIDFILE}
fi
echo "-----------------------"
echo $$
echo $$ > ${PIDFILE}
echo "start to do"
# 所要执行的脚本内容
# cd /home/www/html/gm_server/cmd/email && sudo nohup go run main.go &
echo "----end do----"
cat /dev/null > ${PIDFILE}