Script to check process status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check process status
# 1  
Old 05-07-2015
Script to check process status

Hi Team,
I am using redhat 6.4 version server.We have a script which is used to check the process and sends email if the process is not running.If it is running it will continue and do some other operation.

I didnot understand below option -z in the if condition.I have tried to search in the net for the same but didnot get any related explanation on this.
Code:
if [[ -z `ps -ef | grep /usr/sbin/sshd` ]];then
   echo;echo "The ssd  is not running; exiting."
   exit
fi

My intention here is if the process is not running it should exit from the script and should send an email to the distribution list.It should not continue and do the next tasks if the process is not running.

thanks for your replies.

Regards,
Murali

Last edited by rbatte1; 05-07-2015 at 01:34 PM.. Reason: Changed ICODE tags to CODE tags
# 2  
Old 05-07-2015
man bash:
Quote:
CONDITIONAL EXPRESSIONS
Conditional expressions are used by the [[ compound command ...

-z string
True if the length of string is zero.
# 3  
Old 05-07-2015
Thanks Rudi for your response.But i could see eventhough the ssh process is running it it saying process is not running.Is the above code has any issues?

thanks
# 4  
Old 05-07-2015
Works for me as is. Try to run it with the xtrace option set. Post the output.
# 5  
Old 05-07-2015
I don't see your reported problem, but pgrep solves some potential problems
Code:
if [[ -z `pgrep -u 0 -x sshd` ]];then


Last edited by MadeInGermany; 05-07-2015 at 01:08 PM..
# 6  
Old 05-07-2015
Thanks for your replies.I am able to execute this script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check status of process

Hi All, Have a query How to check for a process and if down start it , try if for 2 times and its not starting don't do it My code is working to some extent but while starting try starting both times. Please advise , whats wrong here ? if you have any other approach please do share. My... (1 Reply)
Discussion started by: abhaydas
1 Replies

2. Linux

Check up the status of a Script (running or not)

Hello, i allready search on google und here in the local Forum, but can't found something. I need a query in php, that check whether a process (script) is running or not. Like this: php query: /usr/bin/Script01 >> if runnig, then: "Script01 is Online", if not "Script01 is Offline" I... (2 Replies)
Discussion started by: ProTechEx
2 Replies

3. Shell Programming and Scripting

How to check the status of script for every 5 min?

Hi, Can any1 provide the code for my req: I am loading few set of files into database through one unix script. I ll try to describe the process: load_cdr-->main script Source Feeds are A & B. File in A-akm.dat File in B-bkm.dat Now my script runs through cron jobs everyday...and for both... (6 Replies)
Discussion started by: gnnsprapa
6 Replies

4. Shell Programming and Scripting

How to check the process status

Hi, I have a cron job which runs every ten minutes, now i hav to check the process whether it is running or not only once and then this should be sent to a log file.. crontab : 00,10,20,30,40,50 * * * * a process check ps = 'ps -ef |grep a ' if then echo " Success" >... (3 Replies)
Discussion started by: NehaKrish
3 Replies

5. Shell Programming and Scripting

How to Check the process Status and do something

Hi we have weblogic deployed under Linux Enterprise 5 . Now i want to write a script that checks if weblogic is running or not I have found that weblogic uses Java as process . Can i do this way : my Script File : Echo Checking Status if then echo Server Running else echo... (2 Replies)
Discussion started by: Ravi Pavanv
2 Replies

6. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

7. Shell Programming and Scripting

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 ; then Banner "Proceesname Problem" else Banner " Running... (5 Replies)
Discussion started by: srinivasvandana
5 Replies

8. Shell Programming and Scripting

check exit status - Expect Script

from my main script, i am calling an expect script. there are a lot of conditions in the Expect script and it can have any exit value based on success or failure of the Expect Script. how can i check the exit status of Expect scritp in the main script. (1 Reply)
Discussion started by: iamcool
1 Replies

9. Shell Programming and Scripting

Script to check status of a PID

i'm just learning scripting, and have been banging my head against this I want to check if my WAS6 java process is running and if so..echo me a messages. If not then echo me a different messages the problem i have is I dont know how to represent a NULL return value. If i grep for a was6... (14 Replies)
Discussion started by: zeekblack
14 Replies

10. UNIX for Dummies Questions & Answers

how to check exit status in awk script

Hi, I have a main program which have below lines - awk -f test.awk inputFileName - I wonder how to check status return from awk script. content of awk script: test.awk --- if ( pass validation ) { exit 1 } else { (1 Reply)
Discussion started by: epall
1 Replies
Login or Register to Ask a Question