防止shell script多次运行
一个思路是在script初期检测系统中是否存在同名进程。
if [ ps -ef | grep "test.sh" | grep -v "grep" | wc -l
-gt 2 ]
then
echo "This script is already running. Exit."
else
while true
do
echo "I am running"
sleep 5
done
fi
如果是第一次运行,那么首行语句检测到的同名进程会有两个:第一个是启动这个script的进程,第二个是反引号内的命令。
Original: https://www.cnblogs.com/byeyear/p/10428020.html
Author: 告别年代
Title: 防止shell script多次运行
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/529741/
转载文章受原作者版权保护。转载请注明原作者出处!