Sponsored Content
Full Discussion: detecting multiple instances
Top Forums Shell Programming and Scripting detecting multiple instances Post 302113381 by vgersh99 on Thursday 5th of April 2007 02:34:36 PM
Old 04-05-2007
here's the paradigm I usually use on Solaris of detecting another instance of the same running script. If another instance IS detected, the current (the calling instance) will exit allowing the 'older' instance to finish its work.

It's not exactly what you want, but might be a good starting point:

Code:
#!/bin/ksh
thisFILE="$(whence ${0})"

progNameFull="${0##*/}"
progName="${progNameFull%%.*}"

AWK='/bin/nawk'
FUSER='/usr/sbin/fuser'

#----------------------------------------------------------------------
# see if there's another instance of THIS script running - don't allow MULTIPLE
# instances of the same script running at the same time. If there's a previously
# invoked instance of this script running, log an error message and exit THIS
# current invocation of the script - allow the previously invoked script finish
# its own workload.
     myPID="$$"
     FUSERout=$(${FUSER} ${thisFILE} 2>/dev/null)
     # echo "fuser ->[${FUSERout}]"
     typeset -i numProc=$(echo "${FUSERout}" | ${AWK} '{print NF}')
     if [[ "${numProc}" -gt 1 ]] ; then
        echo "${progName}::main Error: another instance(s) of [${thisFILE}] is currently still running [$(echo ${FUSERout} | sed -e 's/  */ /g')] - exiting THIS [${myPID}] run."
        exit 1
     fi

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Solaris

ypbind - multiple instances starting

I have built this Solaris 10 server, uses NIS. When the server starts up, two instances of ypbind start. This prevents the server from binding to any domain. The SMF in turn prevents any other network services (sshd and the like) from starting up. Has anyone seen this problem before? (0 Replies)
Discussion started by: blowtorch
0 Replies

4. Shell Programming and Scripting

Multiple instances of a job.

Could you please let me know how to create/make a multiple instances of a job/process in ksh(shell scripting). i.e., at present the parent script is calling another child/dependent script for only once. What we want is, the parent script itself has to execute multiple times, and in each one it... (1 Reply)
Discussion started by: Gangegowda
1 Replies

5. Shell Programming and Scripting

Checking for multiple instances of a process

Hi I have a scenario where i need to check multiple instances of a running shell script (abc.sh) . How can I find from inside a running shell script whether any other instance of the same script is running or not? If any other instance of same shell script is running I need to exit from... (4 Replies)
Discussion started by: raghu.amilineni
4 Replies

6. Shell Programming and Scripting

Grep with multiple instances of same pattern

Hi, This is my text file I'm trying to Grep. Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End My Grep command: grep only--matching 'Location.*Received' e. Because the keyword Received appears twice, the Grep command will stop at the last... (0 Replies)
Discussion started by: spywarebox
0 Replies

7. Shell Programming and Scripting

Grep with multiple instances of same pattern

Hi, This is my text file I'm trying to Grep. Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End My Grep command: grep only--matching 'Location.*Received' Because the keyword Received appears twice, the Grep command will stop at the last... (3 Replies)
Discussion started by: spywarebox
3 Replies

8. 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

9. 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

10. UNIX for Beginners Questions & Answers

Connecting to multiple instances on the same server

I have a db server with two instances...trying to create an expect script that will scan both the listener and the alert log files and retrieve their sizes. Issue we have is that the .profile is hard coded with one of the databases name and script is always pulling from the same instance (testdb1)... (1 Reply)
Discussion started by: donpasscal
1 Replies
VLVINDEX(8)						      System Manager's Manual						       VLVINDEX(8)

NAME
vlvindex - Directory Server script for VLV indexing SYNOPSIS
vlvindex [-Z serverID] -n backendname | {-s includesuffix}* -T vlvTag [-d debuglevel] [-h] DESCRIPTION
Creates virtual list view (VLV) indexes, known in the Directory Server Console as browsing indexes. VLV indexes introduce flexibility in the way search results are viewed. VLV index configuration must already exist prior to running this script. The Directory Server must be stopped before running this script. OPTIONS
A summary of options is included below: -Z Server Identifier The server ID of the Directory Server instance. If there is only one instance on the system, this option can be skipped. -n Backend Name The name of the LDBM database to reindex. Example: userRoot -s includeSuffix Specifies suffixes to be included or the subtrees to be included -T vlvTag This is the name of the vlv index entry under cn=config. -d Debug Level Settings the debugging level. -h Display the usage. EXAMPLE
vlvindex -n userRoot -T myVLVIndex -Z instance2 DIAGNOSTICS
Exit status is zero if no errors occur. Errors result in a non-zero exit status and a diagnostic message being written to standard error. AUTHOR
vlvindex was written by the 389 Project. REPORTING BUGS
Report bugs to http://bugzilla.redhat.com. COPYRIGHT
Copyright (C) 2013 Red Hat, Inc. Mar 5, 2013 VLVINDEX(8)
All times are GMT -4. The time now is 09:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy