sh脚本重复运行判断,禁止开启多个

避免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}		
上一篇:2021-11-14


下一篇:解决element-ui级联选择器,二级三级列表无法显示的解决办法