Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrain running the same script at the same time?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!
Does anyone know how to prevent a script from running again simultaneous with another (This refers to only 1 script program).
Thanks!
Hono'o
 
Use a semaphore/flag like a temporary file or look for the process already running,
'ps -ef' or 'ps -ax'.

Yours Mauro
 
Make sure that your "ps -ef |grep etc..." is unique.
It can happen that you are checking for blabla and someone is Editing blabla.txt.
Your script will not start.
Check for example “grep sh.*blabla” instead.
When you use a lock file make sure the file is deleted when the script exits normally or when it is killed.
Use the trap command to remove the lock file.
Gregor.Weertman@mailcity.com
 
Alternatively, issue a chmod command at the start of the script to remove the execute permissions and then restore them at the end of the script
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top