Results 1 to 4 of 4
Hello All,
Is there any way to prevent users to run the same script at the same time, on the same machine?
Thanks...
- 09-06-2007 #1Just Joined!
- Join Date
- Mar 2006
- Posts
- 25
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
- 09-06-2007 #2Linux Enthusiast
- Join Date
- Jul 2005
- Location
- Maryland
- Posts
- 521
Try using locks. Create lock file before running the script and remove the lock after it finishes. And create condition (in the script) so that script cannot run if there is a lock.
- 09-06-2007 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
If you use a lock file you should put in the script to trap a ^C to abort. Otherwise you'll have the lock file left behind and you'll have to manually delete the file before anyone can run the script again. Here's a crude example:
Code:#!/bin/ksh -vx lkfle="/root/test.lk" if [ -e $lkfle ] then echo "Someone else is running the script" exit fi abort_it () { echo "Aborting" if [ -e $lkfle ]; then rm -fv $lkfle; fi exit } trap abort_it INT touch $lkfle sleep 6 rm -fv $lkfle
- 09-06-2007 #4Just Joined!
- Join Date
- Mar 2006
- Posts
- 25
Thank you very much, you guys are my life savers.


Reply With Quote