![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 11:49 AM |
| verify arguments | bebop1111116 | Shell Programming and Scripting | 2 | 09-19-2006 09:08 PM |
| process already exists | kadishmj | Shell Programming and Scripting | 4 | 06-14-2005 08:41 AM |
| Verify Parameters | lesstjm | Shell Programming and Scripting | 2 | 04-17-2003 05:59 PM |
| Solaris (verify 64 or 32 bit | witt | UNIX for Dummies Questions & Answers | 3 | 11-30-2001 12:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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.) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|