更新时间:2023-10-27 10:23:28
我不能只使用锁定文件并退出,因为不会按任何常规时间表再次调用该脚本.
I can't just use lock files and exit because the script will not be called again on any kind of regular schedule.
在脚本中,在创建锁定文件之前,您可以循环检查锁定文件是否存在,如果存在,则继续循环(通过 sleep
命令或其他方式)以及何时消失,创建它.
Within the script, before creating the lock file, you can loop through checking if the lock file exists, if it does, continue looping (through a sleep
command or something) and when it goes away, create it.
类似的东西:
#!/bin/bash
while [ -e /var/tmp/bash_script.lock ];
do
sleep 5
done
touch /var/tmp/bash_script.lock
echo "do something"
rm /var/tmp/bash_script.lock