Want to have delay in multiple instances of the same shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to have delay in multiple instances of the same shell script
# 1  
Old 05-25-2010
Want to have delay in multiple instances of the same shell script

Hello,
My goal is to run the same Shell script in a parallel mode. This script will get triggered from different machines and different application teams by some job scheduling tool.
They may trigger the process at the same time. so I want to have them in QUEUE ..and release them for execution on first come first server basis (FCFS).
to handle this situation, I am creating one control (dummy) file run_time at particular path and checking the existence of this file for queuing multiple calls for this script.
But as Job scheduling tool is triggering multiple jobs at the same time. By the time first process crates that control file, second job checks and does not find any control file in the given path and it also goes in execution mode instead of waiting mode.
I want to have some delay when job scheduling tool triggers the process at the same time.
How do I handle this in UNIX please?
# 2  
Old 05-25-2010
I prefer to use lock directories instead of lock files. It is not possible, that two concurrent mkdir's both succeed (if you do not use the -p switch). So make a call to mkdir and if you succeed, let your script continue or go into waiting mode otherwise.
# 3  
Old 05-25-2010
In ksh93/bash (maybe other bourne-compatibles too):
Code:
sleep $(( ${RANDOM} % 30 +1 ))

will make your script sleep for a random interval between 1 and 30 seconds.
# 4  
Old 05-25-2010
a simple (but not the safest) way to avoid concurrent runnings of the same script. To write at the beginning
Code:
#!/bin/bash
while pidof -x -o $$ ${0##*/}; do sleep 1; done
(...)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Multiple instances of pthread

Suppose I declare pthread_t clear_thread; and then pthread_create(&clear_thread, &detach, clear_message, this); the thread is supposed to go away, perform the service it is intended to procide, and then kill itself. A little while later, I require this service again, so I say ... (2 Replies)
Discussion started by: clerew
2 Replies

2. Shell Programming and Scripting

How to run multiple instances of shell script in linux?

How we can run the multiple instances of the script? I need to run the script which I am calling from the below function.I can doit with cron but I don't want to put it in the cron.This cript dploy the build and here I want when the build stage then it should run with multilpe instances of... (6 Replies)
Discussion started by: anuragpgtgerman
6 Replies

3. Shell Programming and Scripting

How do I do a short delay (milliseconds) in a shell script?

I need to put a small delay into a shell script. I'm looking for something smaller than "sleep" - a second is way too long. I want to sleep something like 10 milliseconds. I've tried "usleep" and "nanosleep", but the script doesn't recognize them. I'm using the bash shell but I'm willing to... (9 Replies)
Discussion started by: harmlesscat
9 Replies

4. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

5. Shell Programming and Scripting

How to introduce delay in Shell Script till a key stroke.

Hi All, How to introduce delay in the Bash/Shell Script till key stroke. Below is the requirement.. 1.Execute set of commands. 2.Display the message echo "press any key to continue" Introduce a delay till key stroke. 3.Execute next set of commands. Thanks in Advance Sunil.K (5 Replies)
Discussion started by: sunilrk07
5 Replies

6. Shell Programming and Scripting

Get the STATE of the weblogic instances via shell script.

Can I get the STATE(instance are RUNNING or not and HEALTH is OK or not) of the weblogic instances(Admin and Managed) running on my unix machine via shell script. Someone told me that it can be done via "weblogic.Admin GETSTATE"....but it is not working for me(might be I am doing something wrong)... (2 Replies)
Discussion started by: joshilalit2004
2 Replies

7. Shell Programming and Scripting

Multiple instances of the job in shell script.

Hi, Please let us know how to create a multiple instances of a job in the shell script. Thanks. Gangegowda K.G (1 Reply)
Discussion started by: Gangegowda
1 Replies

8. Filesystems, Disks and Memory

script to create multiple instances of a user account across LPAR's

My company has about 40 databases with each database in a different logical partition. Presently the SysAdmin person says it is necessary to create a user profile (login and password for each instance of databases on each LPAR. 1. Is it necessary that the user must be created in each LPAR? 2.... (1 Reply)
Discussion started by: kcampbell
1 Replies

9. UNIX for Dummies Questions & Answers

Multiple file instances

I am capturing text based reports with a specific program, which works no problem. However, since I send report warehouse output as they are migrated from the database software, on occasion when two capture process' initiate simultaneously, the capture file locks up. Is there a way to setup (in... (1 Reply)
Discussion started by: gozer13
1 Replies

10. UNIX for Advanced & Expert Users

multiple instances of syslogd - is it possible?

I would like to start up multiple instances of syslog daemon. I am having a little difficulty. Is this at all possible? I have separate syslog.conf1.... syslog.conf5 files. I have linked the daemon to separate files syslogd1 ... syslogd5 I have arranged the rcd.2 start/stop scripts for... (9 Replies)
Discussion started by: Gary Dunn
9 Replies
Login or Register to Ask a Question