Ps -ef|grep <processname> usage in IF statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ps -ef|grep <processname> usage in IF statement
# 1  
Old 07-17-2013
Ps -ef|grep <processname> usage in IF statement

Hi,

Am working in a filenet domain where we are using AIX as our terminal to run the jobs and schedule the shell scripts to run . In my previous post regarding the "Log modification with finding errors" https://www.unix.com/shell-programmin...nt-time-2.html Gabriel has helped me thoroughly to complete the entire script. Thanks for the help Gab. The script was sent to my leads to get their reviews. Will keep you posted there if i get any updates.

The next thing which i started here to begin our conversation is - In filenet there are 4 image services HPII COLD POST BES.

When we give ps -ef|grep HPII , it will display a output ending with ./HPII_import and ./HPII_val.

When we give ps -ef|grep cold , it will display a output ending with ./cold_daily.ksh and COLD_3770.

When we give ps -ef|grep bes_commit , it will display a output ending with bes_commit 1 and bes_commit 2

When we give ps -ef|grep post , it will display a output ending with
./postindex_daily.ksh

I need to use a IF condition added with the above ps statements, if the resulting output comes it should send us a status , for HPII - " HPII is running fine without any issues ". for post - "POST Index services is fine" . same for other too.

Could some one help me out with this IF conditional statement added with PS . I should schedule this script for every 1 hour. NOTE: This should work in AIX terminal.
# 2  
Old 07-18-2013
Use -q (quiet option of grep):

Code:
ps -ef | if grep -q '[H]PII'
then
   echo "HPII is running fine without any issues"
fi

Note square brackets avoid grep matching it's own arguments in the ps listing.
# 3  
Old 07-18-2013
Thanks for the reply,

So do i need to add the script by square brackets as you said
ps -ef | if grep -q '[H]PII' then echo "HPII is running fine without any issues" fi
ps -ef | if grep -q '[p]ost' then echo "HPII is running fine without any issues" fips -ef | if grep -q '[b]es_commit' then echo "BES is running fine without any issues" fips -ef | if grep -q '[c]old' then echo "COLD is running fine without any issues" fi
# 4  
Old 07-18-2013
Please wrap your code in [code] tags! (At the top of the WIKI editor.)
--
Square brackets is a trick only for ps -ef | grep, so YES in this case. pgrep is a smart alternative on many platforms.
--
I would use if at the beginning of the command block, aligned with the fi at the end of the command block.
Either #1
Code:
ps -ef |
if grep -q ...
then
 ...
fi

Or #2
Code:
if ps -ef | grep -q ...
then
 ...
fi

I wonder if there is any functional difference between #1 and #2, because in #2 the resulting exit status is from the last command in the pipe.
In fact I am used to #2.
# 5  
Old 07-18-2013
I'd be surprised if ps -ef|grep cold yielded COLD_3770 (unless GREP_OPTIONS is set).
And, for HPII to be considered running fine, do you need both processes (_import and _val)? Then you should test for both of them. Same is valid for the other applications.
# 6  
Old 07-22-2013
Thanks for the reply ,

Yeah when i give ps -ef|grep cold it shows the output of cold_3770 (sorry its not COLD_3770). And of course i need to validate 2 HPII process (HPII_val and HPII_import). Could you please help me out with this.
# 7  
Old 07-22-2013
Try
Code:
ps -ef|
awk     '/HPII_val/     {HPV=1}
         /HPII_imp/     {HPI=1}
         /cold_dai/     {CDD=1}
         /cold_377/     {CD7=1}
         /bes_commit 1/ {BC1=1}
         /bes_commit 2/ {BC2=1}
         /post_ind/     {POI=1}
         END            {if (HPV && HPI) print "HPII is running fine without any issues"
                         if (CDD && CD7) print "COLD is running fine without any issues"
                         if (BC1 && BC2) print "BES is running fine without any issues" 
                         if (POI)        print "POST Index services is fine"
                        }
        '

and report back.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arguments in usage statement

Hello, I have a question regarding the usage statement of a script. I have 2 parameters "--pto" and "--pto_list". To start the script I will need one of them. Both together are not possible. How this would be printed out within a usage statement? My suggestion would be: Usage:... (4 Replies)
Discussion started by: API
4 Replies

2. Homework & Coursework Questions

grep usage help?

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to find all the files where the function sequentialInsert is called and the directory is ~cs252/Assignments/commandsAsst/project 2.... (2 Replies)
Discussion started by: jennkat
2 Replies

3. Shell Programming and Scripting

usage of case statement in place of IF elif...

Hi, I need to carry out the back up of the data if exists...(file size not equal to zero) i tried in this way but it is not successful....where am making the mistakes? and if possible can i use case syntax in place of "if" #!/bin/ksh filename=`TZ=CST+24 date +%Y%m%d` ZERO=0... (3 Replies)
Discussion started by: aemunathan
3 Replies

4. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

5. UNIX for Advanced & Expert Users

Grep usage

my file contains xxabced.p dlksfad; dflsdkjflkds flksdjflkdioewf erfsdlkfjsdla; dlkfjsd;lfkj msgdadf.p dslk kdjflksdjfl;asdfasdfjkljl fdsf;jd ppuskldf.p i want the output is xxabced.p msgdadf.p ppuskldf.p Can any one give the command? (1 Reply)
Discussion started by: kingganesh04
1 Replies

6. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

7. UNIX for Dummies Questions & Answers

Grep Usage

Hello, I am trying to use grep to locate multiple uses of the same word in the same line. The word has to be 3+ char, upper or lower or both. I tried this code <code> grep \({3,}\)*\1 i* </code> and i turned out zero results. Any ideas? ____________________________________________... (5 Replies)
Discussion started by: Omega1589
5 Replies

8. UNIX for Dummies Questions & Answers

PID - Getting the processname of terminated/old Process

Hi all! I'm using CentOS 5.2 with KDE. Is it possible to get a processname/cmd of a terminated process (= PID not present with PS-command) ? Are the processnames/scriptnames logged somewhere? (I did not find them in /var/log/messages) (5 Replies)
Discussion started by: JohnMurdoch
5 Replies

9. UNIX for Dummies Questions & Answers

Grep usage help

Hello, I have a list in .txt format of email addresses and I need to extract just a specific domain ... The list format is like: "123456";"user@domain.com";"email";"john";"name" "123457";"user2@domain.com";"email";"john";"name" "123458";"user3@domain.com";"email";"john";"name"... (7 Replies)
Discussion started by: holyearth
7 Replies

10. UNIX for Advanced & Expert Users

grep usage

grep can filter the text which want to display, but if I want it do not show the text specific in grep, how to do? thk a lot! (2 Replies)
Discussion started by: zp523444
2 Replies
Login or Register to Ask a Question