LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   prevent users to run the same script at the same time, on the same machine (https://www.linuxquestions.org/questions/programming-9/prevent-users-to-run-the-same-script-at-the-same-time-on-the-same-machine-582521/)

pvpnguyen 09-05-2007 08:34 PM

prevent users to run the same script at the same time, on the same machine
 
Hello All,

Is there any way to prevent users to run the same script at the same time, on the same machine?

Thanks

cfaj 09-05-2007 08:46 PM

Quote:

Originally Posted by pvpnguyen (Post 2882642)
Is there any way to prevent users to run the same script at the same time, on the same machine?


Create a directory in /tmp; if you cannot create the directory,
someone else is already using the script.

Be sure to remove the directory when the script exits:

Code:

mkdir /tmp/${0##*/}-running 2>/dev/null || {
  echo script already running
  exit
}
trap 'rmdir /tmp/${0##*/}-running' EXIT


pvpnguyen 09-05-2007 08:52 PM

Thank you very much , Will this cover the case that the user hits Crtl-C?


All times are GMT -5. The time now is 02:36 PM.