OpenSolaris Solaris Forum  
     

Left Nav Register FAQ Members List Default Password Members List Linux Commands Search Today's Posts Mark Forums Read Right Nav

Left Container Right Container
 

Go Back   OpenSolaris Solaris Forum » Solaris General

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2011, 07:16 AM
Junior Member
 
Join Date: Feb 2011
Posts: 1
Question Find the number of script instances running

Hi,
I have a script which I run through cron every xx minutes. In the script I check if it is already running, if it is already running I need to exit the script.
I have used the below logic to get the number of instances. However occasionaly it is giving wrong values. Why does it happen and how do I fix it.
Below I have pasted the script and the output. The output of just the grep command is also pasted at the end. Any help is greatly appreciated.

SCRIPT:

Code:
#!/bin/sh
instance=`ps -ef|grep "/bin/sh"|grep "testSCRIPT.sh"|egrep -v '\-c|grep'|wc -l`
echo $instance 
echo `date`
echo "######################"

OUTPUT:
2
Fri Feb 18 11:34:05 IST 2011
######################
2
Fri Feb 18 11:35:06 IST 2011
######################
1
Fri Feb 18 11:36:06 IST 2011
######################
3
Fri Feb 18 11:37:05 IST 2011
######################
1
Fri Feb 18 11:38:05 IST 2011
######################
OUTPUT OF GREP
root 24951 15758 0 13:05:50 pts/6 0:00 /bin/sh ./testSCRIPT.sh
root 24953 24951 0 13:05:50 pts/6 0:00 /bin/sh ./testSCRIPT.sh
Reply With Quote
Sponsored Links

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check number of CPUs in Solairs ? Unregistered Hardware Problems 3 01-22-2011 08:57 AM
Find Solaris Serial Number Unregistered Solaris OpenSolaris Servers 2 06-29-2010 03:33 PM
How can I find port on which VNC is running Unregistered Solaris General 1 03-27-2010 11:27 AM


All times are GMT. The time now is 02:02 PM.


Powered by vBulletin. Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.