The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 11:50 AM
Survey finds Windows losing ground with developers - Computerworld New Zealand iBot UNIX and Linux RSS News 0 07-09-2007 08:40 AM
SETI Finds Stolen Laptop Perderabo News, Links, Events and Announcements 2 04-05-2007 11:14 PM
fixing the error message when grep doesn't finds the pattern. silver123 UNIX for Dummies Questions & Answers 1 03-03-2006 05:59 AM
Appending to filename a string of text grep finds HLee1981 Shell Programming and Scripting 3 09-06-2005 03:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-28-2001
jguirao jguirao is offline
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 05:40 PM..
  #2 (permalink)  
Old 02-28-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
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 05:40 PM..
  #3 (permalink)  
Old 02-28-2001
jguirao jguirao is offline
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 Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
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
jguirao jguirao is offline
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 03-01-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
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 05: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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not 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




All times are GMT -4. The time now is 08:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0