verify if a process exists (ps)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting verify if a process exists (ps)
# 1  
Old 05-30-2007
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  
Old 05-30-2007
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 01:02 PM..
# 3  
Old 04-04-2008
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  
Old 04-05-2008
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  
Old 04-05-2008
Another option is to use pgrep is it is available on your system
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Verify if filename exists

Hi, I have a variable returned from Oracle SQL Function which holds file names. I would like to test if all the file names mentioned in the string exists in a directory. If all the files exists print "exists", even if one file does not exists print "Does not exists". e.g. ... (3 Replies)
Discussion started by: pointers1234
3 Replies

2. Red Hat

Verify multipathing

I have a couple of questions regarding multipath. If I do vgdisplay vg01, I see it is using 1 PV: /dev/dm-13 If I type multipath -ll I see dm-9, dm-10, dm-11, dm-12, but do not see dm-13. Is my vg01 multipathed? How can I actually know for sure? Secondly, let's say this time vg01 says... (1 Reply)
Discussion started by: keelba
1 Replies

3. Hardware

Verify patching

I patched a linux kernel 2.6.28 with lttng patch. Now I have two folder of linux patched and unpatched. How can I verify whether the linux is patched or unptahced(original version)? (0 Replies)
Discussion started by: rupeshkp728
0 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. Shell Programming and Scripting

How to verify process as uppercase

Hi, I'm using ksh, I have a server process run in the background called fin_tr_APPADJ. I have a requirement now to create a script to check if all the processes spawn with process named fin_tr_* must be uppercase, fin_tr_ can be lower case, but anything suffixed with fin_tr_* must be uppercase.... (4 Replies)
Discussion started by: khchong
4 Replies

6. Shell Programming and Scripting

Verify File exists and execute command

Hi, I am trying to verify that a file exists within an alternate directory. If the file exists, it will execute a copy command...if it does not, it should exit the script. I tried the <test> command and the but keep coming up with syntax errors. I am coding in C Shell and the file... (5 Replies)
Discussion started by: CKT_newbie88
5 Replies

7. AIX

verify command

Guy's I have script doing many steps as the below ... ############# ## step1# mount all Files system mount all ## step2# Start the application /app/appsh ############# but some time mount points will not be mounted completely so that will give an error if the next step started... (1 Reply)
Discussion started by: Mr.AIX
1 Replies

8. Shell Programming and Scripting

Script to delete a process if it exists

I have an application that uses java but when the application stops, sometimes, for some odd reason, it leaves java threads behind. When the application next starts, it doesn't behave properly because of these previous java processes What I want to do is create a script to check for these java... (2 Replies)
Discussion started by: davidra
2 Replies

9. HP-UX

How to verify the size of a process

Hi, Could you please advise on the command to verify the size of a process in HPUX 11.23 Itanium. The process name is arserverd. Many thanks in Advance, Best Regards, John Joseph (2 Replies)
Discussion started by: jjosephHPUX
2 Replies

10. Shell Programming and Scripting

process already exists

I'm attempting to modify a script that ftps files from one machine to another (see this post ). I've been testing it a few times, and once I had to kill the test because it was taking forever, and I know it wasn't working. Now, when I try to test the script again, I'm getting the following: $... (4 Replies)
Discussion started by: kadishmj
4 Replies
Login or Register to Ask a Question