Quick-and-dirty way to ensure only one instance of a shell script is running at a time

前端 未结 30 3031
忘掉有多难
忘掉有多难 2020-11-22 02:57

What\'s a quick-and-dirty way to make sure that only one instance of a shell script is running at a given time?

30条回答
  •  耶瑟儿~
    2020-11-22 03:07

    Quick and dirty?

    #!/bin/sh
    
    if [ -f sometempfile ]
      echo "Already running... will now terminate."
      exit
    else
      touch sometempfile
    fi
    
    ..do what you want here..
    
    rm sometempfile
    

提交回复
热议问题