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 > 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
SCO Backups and Verify Log jfd7000 SCO 1 04-28-2008 10:49 AM
verify arguments bebop1111116 Shell Programming and Scripting 2 09-19-2006 08:08 PM
process already exists kadishmj Shell Programming and Scripting 4 06-14-2005 07:41 AM
Verify Parameters lesstjm Shell Programming and Scripting 2 04-17-2003 04:59 PM
Solaris (verify 64 or 32 bit witt UNIX for Dummies Questions & Answers 3 11-30-2001 12:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-30-2007
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
verify if a process exists (ps)

hi

I want to verify that a process exists. if the process exists, then it means the service is up.

ps -ef | grep monito
returns an entry if the service is up.

how to translate that in a shell script??

many thanks
  #2 (permalink)  
Old 05-30-2007
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,358
Code:
if ps -ef | grep -q [m]onito
then
   echo "Service is up"
else
   echo "Service is down"
fi
Jean-Pierre.

Last edited by aigles; 05-30-2007 at 12:02 PM..
  #3 (permalink)  
Old 04-04-2008
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
hi

I have a sybase server. I want to check if the server is up using ps -aef | grep dataserver

What is the exit status to be checked? that of ps or grep?
If I should check ps exit status, the server can be down and ps exit code will be as if the server is up. right?

So I should check the exit status of grep.

how to do that in a shell script?

thx
  #4 (permalink)  
Old 04-05-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
Executive summary: You already got the answer. ps lists all processes, and grep checks if the selected process is among them.

Every command in a shell script sets its exit status. The exit status of a pipeline is the exit status of the last command in that pipeline. The exit status is available in the variable $? but the idiomatic way to do this is usually with an if statement, like the one aigles already posted.

if executes the commands you give it as parameters, and takes the then branch if the exit status was zero (meaning success) and the else branch otherwise. If the selected branch is missing, it does nothing. (Some shells allow the then branch to be left out, but this is not entirely portable; in all events, the else branch is optional.)
  #5 (permalink)  
Old 04-05-2008
fpmurphy's Avatar
fpmurphy fpmurphy is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,863
Another option is to use pgrep is it is available on your system
Sponsored Links
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 12:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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