确保在给定时间只运行一个shell脚本实例的快速而简单的方法是什么?
GNU bash,版本1.14.7(1)
我有一个脚本被称为" abc.sh"我必须从abc.sh脚本中检查这个...在其中我写了以下语句
status=`ps -efww | grep -w "abc.sh" | grep -v grep | grep -v $$ | awk '{ print $2 }'`
if [ ! -z "$status" ]; then
echo "[`date`] : abc.sh : Process is already running"
exit 1;
fi
Run Code Online (Sandbox Code Playgroud)
我知道这是错的,因为每次它退出,因为它在'ps'中找到了自己的进程如何解决它?如何检查脚本是否已经运行from that script?