The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Aite Group Finds Huge Gains for CEP iBot Complex Event Processing RSS News 0 02-06-2008 07:50 AM
Survey finds Windows losing ground with developers - Computerworld New Zealand iBot UNIX and Linux RSS News 0 07-09-2007 04:40 AM
SETI Finds Stolen Laptop Perderabo News, Links, Events and Announcements 2 04-05-2007 07:14 PM
fixing the error message when grep doesn't finds the pattern. silver123 UNIX for Dummies Questions & Answers 1 03-03-2006 01:59 AM
Appending to filename a string of text grep finds HLee1981 Shell Programming and Scripting 3 09-06-2005 11:44 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-28-2001
Registered User
 

Join Date: Feb 2001
Posts: 5
Angry

Hello,

I have problems executing a script in ksh with this script named
process.sh:
Code:
ps -ef | grep process.sh | grep -v grep | wc -l | read a
if [ $a -gt 1 ]
then
 echo "The script is running" 
exit 0
fi
The problem is that when I execute the script, sometimes it shows the
message "The script is running", when I think it's impossible.
The reason that I write "wc -l|read a" is that
the count returns 1 because the "ps" is executed in the same script.
My idea is that nobody execute 2 times the same script, only on time.

Is something wrong?

Thanks in advance.

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:40 PM.
Forum Sponsor
  #2 (permalink)  
Old 02-28-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 905
How about:
Code:
#!/bin/ksh

ps -ef | grep "[p]rocess.sh" 1> /dev/null 2>&1
if [$? -eq 0]
then
	echo "script is running"
	exit 0
fi
exit 1
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:40 PM.
  #3 (permalink)  
Old 02-28-2001
Registered User
 

Join Date: Feb 2001
Posts: 5
Unhappy

The script is always running 1 time, I must insert the code in the same script to control if someone will execute the script again.
  #4 (permalink)  
Old 02-28-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 905
Ok, I understand now. Why don't you make the script test for a lockfile when it starts?

if [ -a /tmp/process.lock ]; then
exit
fi

touch /tmp/process.lock
# rest of script
rm /tmp/process.lock
  #5 (permalink)  
Old 02-28-2001
Registered User
 

Join Date: Feb 2001
Posts: 5
Your idea is good, but I need to implement it in a lot of scripts (77 aprox), a lot of them running at the same time.

What I don't want is to use 77 different names for each temporary file.

  #6 (permalink)  
Old 02-28-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 905
Ok, third time's a charm...

What about:
Code:
#!/bin/ksh
NUM=`ps -ef | grep "[p]rocess.sh" | wc -l
if [ $NUM -gt 1 ] 
then 
            echo "The script is running" 
            exit 0 
fi
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:40 PM.
  #7 (permalink)  
Old 03-01-2001
mib mib is offline
Registered User
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
Quote:
#!/bin/ksh
NUM=`ps -ef | grep "[p]rocess.sh" | wc -l
Script is perfect.

But it lost closing quote. isn't it?
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:22 PM.


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

Content Relevant URLs by vBSEO 3.2.0