LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-05-2007, 08:34 PM   #1
pvpnguyen
Member
 
Registered: Mar 2006
Posts: 38

Rep: Reputation: 15
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
 
Old 09-05-2007, 08:46 PM   #2
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by pvpnguyen View Post
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
 
Old 09-05-2007, 08:52 PM   #3
pvpnguyen
Member
 
Registered: Mar 2006
Posts: 38

Original Poster
Rep: Reputation: 15
Thank you very much , Will this cover the case that the user hits Crtl-C?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run one script, but execute commands at the same time Micro420 Programming 8 07-18-2007 12:05 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
Script that will run a command, time it etc. kinetik Programming 7 06-20-2006 04:42 PM
Run script each time cd is used c19h28O2 Linux - Newbie 14 05-02-2006 04:19 PM
How run script after certain idle time? nio Linux - Software 2 07-09-2005 02:05 PM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration