Sponsored Content
Top Forums Shell Programming and Scripting How to limit the number of running instances of a script? Post 52779 by jim mcnamara on Friday 25th of June 2004 03:31:15 PM
Old 06-25-2004
Another fairly robust solution is to create a lock file:

Code:
#!/bin/ksh

# check for existence of a lock file
# if the file exists make sure the pid that 
#          created it is still running then exit.
if [ -e /tmp/myshellscript.lock ]; then 
         pid=`cat /tmp/myshellscript.lock`
         ps -p "$pid" >/dev/null 2&>1
# somebody else is running the script ?
         if [ $? -eq 0]; then
                echo "another processi is running - try again later"
                exit 1
         fi
# put the current process as owner of the lock
         echo "$$" > /tmp/myshellscript.lock

else
# no file found - make one, own the lock,too.

         echo "$$" > /tmp/myshellscript.lock
         chmod 777 /tmp/myshellscript.lock
fi
...

.....
# last lines of script - release lock file
rm -f /tmp/myshellscript.lock
exit 0

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script that checks for previous instances running

Hello, I'm trying to write a script that checks for previous instances of the same script which may still be running (this script is scheduled to run every 30 minutes). I want to somehow use the pid from each instance to make sure the previous one isn't running before continuing with my... (5 Replies)
Discussion started by: bd_joy
5 Replies

2. Shell Programming and Scripting

Awk - Count instances of a number in col1 and put results in a col2 (new) of diff file

I have 2 files as follows: filename1: : 6742 /welcome/mundial98_ahf1_404.htm 1020 6743 /welcome/mundial98_ahf1_404.htm 2224 6744 /welcome/mundial_ef1_404.htm 21678 6745 /welcome/mundial_if_404.htm 4236 6746 /welcome/mundial_lf1_404.htm 21678 filename2: 6746 894694763 1... (2 Replies)
Discussion started by: jontjioe
2 Replies

3. UNIX for Advanced & Expert Users

Limit on Number of Cron Jobs Running on one Account

Hello, I have some 150 Cron Jobs running under my UNIX account. I want to add some more jobs. Is there a limit to the number of cron jobs that can be run on an account? Thank you. Pramodini (8 Replies)
Discussion started by: Pramodini Rode
8 Replies

4. Shell Programming and Scripting

count and number instances of a character in sed or awk

I currently use LaTeX together with a sed script to set cloze test papers for my students. I currently pepend and equals sign to the front of the words I want to leave out in the finished test, =perpendicular, for example. I am able to number the blanks using a variable in LaTeX. I would like to... (8 Replies)
Discussion started by: maouinin
8 Replies

5. Shell Programming and Scripting

Running script automatically when threshold limit met in one of the field in oracle database

Hi Guys, Need you help in one point! I am working on one shell script which takes following steps : 1. Taking one query result from oracle database 2. Exporting that result to Xls file 3. Mailing that file to my own mail ID Now, I want to give a threshold limit to one of the column... (0 Replies)
Discussion started by: Agupte
0 Replies

6. Shell Programming and Scripting

Script counting instances of software running on a machine

Hello to all @here, as Iīm new to this forum, I will try to start in a easy way for my first post. Iīm not beginner in scripting, but also not a proffessional. So please keep easy, if I donīt understand your explanation at once ;) I donīt mean it in a bad way! Here is the Problem: There were... (2 Replies)
Discussion started by: muogli
2 Replies

7. Shell Programming and Scripting

How to use counter to run the script to limit number?

I want to run my shell script to the limit number.Suppose I know in advance that MAX=5 then I want that my script run 5 times only.Something like below$ vi testingMAX=5COMMAND="ssh -l stpuser VHLDVWSAD001 /projects/st/utils/deploy/deployall.sh >/dev/null 2>&1 &" ; sleep 20;count=0while... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

8. Shell Programming and Scripting

A script that kills previous instances of itself upon running not killing child processes

I'm likely going to explain this clumsily, so apologies in advance: I have the following script: #!/bin/bash pidPrefix="logGen" checkPrime () { if /sbin/ifconfig eth0:0|/bin/grep -wq inet;then isPrime=1;else isPrime=0;fi } killScript () { /usr/bin/find /var/run -name... (4 Replies)
Discussion started by: DeCoTwc
4 Replies

9. Shell Programming and Scripting

count the number of instances in 2 columns using awk

Input A.1 Q.1 A.1 Q.2 A.1 Q.3 A.2 Q.4 Explanation: Final Output A.1 Q.1 s1 t1 A.1 Q.2 s1 t2 A.1 Q.3 s1 t3 A.2 Q.4 s5 t5 ---------- Post updated 09-28-12 at 03:38 AM ---------- Previous update was 09-27-12 at 09:10 AM ---------- Hi Guys, I was able to do until... (11 Replies)
Discussion started by: quincyjones
11 Replies

10. Shell Programming and Scripting

Limit on number of pipes after long-running command?

I'm trying to create a minimal, crude keylogger for X using only a shell script. I was quickly stumped: Why do these two commands entered in a terminal emulator produce output when I type... $ xinput test 6 | grep press $ xinput test 6 | awk '{print $3}' ...but this command produces no... (13 Replies)
Discussion started by: DevuanFan
13 Replies
INSTANCES.CONF(5)						  [FIXME: manual]						 INSTANCES.CONF(5)

NAME
instances.conf_ - zorp(8) instances database DESCRIPTION
The instances.conf file describes the zorp(8) instances to be run on the system. It is processed by zorpctl(8) line by line, each line having the structure described below. Empty lines and lines beginning with '#' are comments ignored by zorpctl. STRUCTURE
instance-name parameters [-- zorpctl-options] instance-name is the name of the Zorp instance to be started; it is passed to zorp with its --as parameter. Instance names may consist of the characters [a-zA-Z0-9_] and must begin with a letter. parameters are space separated parameters entered into the zorp command-line. For details on these command-line parameters see zorp(8). zorpctl-options are space separated parameters control startup specific options. They are processed by zorpctl itself. The following zorpctl options are available: --auto-restart or -A Enable the automatic restart feature of zorpctl. When an instance is in auto-restart mode, it is restarted automatically in case the instance exits. --no-auto-restart or -a Disable automatic restart for this instance. --fd-limit <number> or -f <number> Set the file descriptor limit to <number>. The file descriptor limit defaults to the number of threads (specified by the --threads parameter of zorp(8)) multiplied by 4. --process-limit <number> or -p <number> Set the process limit to <number>. The process limit defaults to the number of threads (specified by the --threads parameter of zorp(8)) multiplied by 2. --enable-core Explicitly enable core dumps for Zorp processes. The core limit is inherited from the local starting environment (e.g.: starting shell) if not specified. --parallel-instances <number> or -P <number> Run <number> of processes for the instance. zorpctl starts exactly one Zorp process in master mode and <number> of slave Zorp processes. This mode of operation is incompatible with old-style dispatchers, you must use the new rule-based policy with this option. EXAMPLES
zorp_ftp --policy /etc/zorp/policy.py --verbose 5 The line above describes a Zorp instance named zorp_ftp using policy file /etc/zorp/policy.py, and having verbosity level 5. zorp_intra -v4 -p /etc/zorp/policy.py --threads 500 --no-auto-restart --fd-limit 1024 --process-limit 512 This line describes a zorp instance named zorp_intra using the policy file /etc/zorp/policy.py, verbosity level 4. The maximum number of threads is set to 500, file descriptor limit to 1024, process limit to 512. FILES
The default location of instances.conf is /etc/zorp/instances.conf. Defaults for zorpctl tunables can be specified in /etc/zorp/zorpctl. AUTHOR
This manual page was written by the BalaBit Documentation Team <documentation@balabit.com>. COPYRIGHT
Copyright (C) 2006 BalaBit IT Security Ltd. All rights reserved. For more information about the legal status of this document please read: http://www.balabit.com/products/zorp/docs/legal_notice.bbq [FIXME: source] 03/06/2012 INSTANCES.CONF(5)
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy