The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CPU usage and memory usage mansoorulhaq High Level Programming 1 08-09-2007 01:55 PM
Getting CPU Usage WG1 Shell Programming and Scripting 4 05-01-2006 05:07 AM
Monitor CPU usage and Memory Usage Gajanad Bihani High Level Programming 2 03-09-2005 04:35 AM
cpu usage sushaga Filesystems, Disks and Memory 0 04-06-2002 05:46 AM
CPU usage Karen UNIX for Dummies Questions & Answers 2 11-04-2001 04:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-07-2008
Registered User
 

Join Date: Oct 2007
Posts: 61
usage of ps -ef

Hi,
I can have only one instance of my script running at any point of time. So I have :
SCRIPT_NAME=$0
if [ `ps -ef | grep " ${SCRIPT_NAME}" | grep -v "grep" | wc -l` -gt 1 ]; then
echo "The process $0 is already running. Aborting the current instance of the job $0"
exit 1

fi


And in the last line of the script i had given exit 0

At times, though the script is not running, i get an error "The process is already running ..." and my script get aborted. So wat can be done for this ?

My requirement is I will scheudle this scirpt in autosys and will be executed every half an hour. And only one instance of the script should be executed at any point of time.

Can any one please help me ??

thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 07-07-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 958
Echo $SCRIPT_NAME and compare it what ps -ef give as output. Maybe they are slightly different and so grep can't find it that way. Maybe you got to parse or escape the leading ./ when you call it.
Reply With Quote
  #3  
Old 07-07-2008
Registered User
 

Join Date: Oct 2007
Posts: 61
I tired that too..
That is giving correctly..

wat else can be done ...
Reply With Quote
  #4  
Old 07-08-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 958
Your script works - I added an infinite loop so I have that script constantly running in the background. Started it with nohup & in the background and tried to start that script again:

Code:
root@isau02:/data/tmp/testfeld> ./loop.ksh
exit code: 0
script name: ./loop.ksh
The process ./loop.ksh is already running. Aborting the current instance of the job ./loop.ksh
root@isau02:/data/tmp/testfeld> ps -ef| grep -i loo
root     29647 32139  0 09:25 pts/0    00:00:00 /usr/bin/ksh ./loop.ksh
root     29685 29659  0 09:26 pts/1    00:00:00 grep -i loo


root@isau02.debeka.de:/data/tmp/testfeld> cat loo*
#!/usr/bin/ksh

typeset -i A=0
SCRIPT_NAME=$0

if [ `ps -ef | grep " ${SCRIPT_NAME}" | grep -v "grep" | wc -l` -gt 1 ]; then
        echo "exit code: $?"
        echo "script name: ${SCRIPT_NAME}"
        echo "The process $0 is already running. Aborting the current instance of the job $0"
        exit 1
fi

while (( $A != 1 )); do
        sleep 1
done

exit 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
autosys

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0