The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to check the FTP Status? smc3 Shell Programming and Scripting 1 06-24-2008 06:15 PM
Start time/end time and status of crontab job thambi Shell Programming and Scripting 3 05-16-2007 11:24 AM
check the status and send an email with status isingh786 Shell Programming and Scripting 3 12-29-2005 07:22 PM
performing a task at regular intervals mridula High Level Programming 2 11-14-2005 05:26 AM
mailing myself at regular intervals... timepassman Shell Programming and Scripting 4 08-21-2005 09:11 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 07-26-2008
srinivasvandana srinivasvandana is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Post Pls Help me out ... I want to check process status at regular intervals of time

I want to check process status at regular interval of time ...
so i ha wirtten this BUT its not working when i placed this peace of code in .sh ..
please help me out

#!/bin/sh
w = ps -ef|grep processname | wc - l
echo $w
if [ $w -lt 3 ] ; then
Banner "Proceesname Problem"
else
Banner " Running Fine"
fi

Please help me out with necessary modification .
Thanks in advance...
  #2 (permalink)  
Old 07-26-2008
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,811
try code tags....


Code:
#!/bin/sh
w = $(ps -ef|grep $processname | grep-v 'grep' | wc - l )
echo $w
if [ $w -lt 3 ] ; then 
echo "$processname Problem"
else 
echo " Running Fine"
fi

  #3 (permalink)  
Old 08-02-2008
srinivasvandana srinivasvandana is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
hi jim,
Thank you very much,
I got the solution and the problem is when we are trying taking variable "w" it is giving some errors i think "w" is internal system parameter .
I tried it with taking "t" as variable it got executed.

Thank you once again for helping me out JIM.

Lastly i have one dought "ps -ef|grep $processname | grep-v 'grep' | wc - l"
why did you grep -v 'grep' i havent used like this any time.
  #4 (permalink)  
Old 08-02-2008
japetmendoza japetmendoza is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Hi Srini,

grep -v 'grep' would tend to filter the process output, not to include grep process.. Remember that it may be included as a process, and would confusions. So to be safe, that was added...
Quote:
Originally Posted by srinivasvandana View Post
hi jim,
Thank you very much,
I got the solution and the problem is when we are trying taking variable "w" it is giving some errors i think "w" is internal system parameter .
I tried it with taking "t" as variable it got executed.

Thank you once again for helping me out JIM.

Lastly i have one dought "ps -ef|grep $processname | grep-v 'grep' | wc - l"
why did you grep -v 'grep' i havent used like this any time.
  #5 (permalink)  
Old 08-02-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,447
Quote:
Originally Posted by srinivasvandana View Post
...
w = ps -ef|grep processname | wc - l
echo $w
if [ $w -lt 3 ] ; then
....
You can replace ps, grep and wc by pgrep

Code:
#!/bin/sh
if [ $(pgrep -c processname) -lt 3 ] ; then 
       echo "$processname Problem"
else 
       echo " Running Fine"
fi

  #6 (permalink)  
Old 08-02-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
See also http://www.unix.com/unix-advanced-ex...-new-post.html
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 10:42 PM.


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