process filtering


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting process filtering
# 1  
Old 04-08-2005
Question process filtering

Smilie Hello,
i have written a mail previously but now i have written a script to monitor the status of the unix system process,in which i redirect the out put to file now i have a problem filtering the process that are running and stopped. in fact i want to filter for the processes that have stoped and send the list via mail. ( i can manage the ma
can some one help me on this

below is code, if some one can suggest me some better method i would be very thakful

#!/bin/ksh
# Korn shell script
rm /tmp/psout.txt
ps -efl > /tmp/psout.txt


sample out put:
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
19 T root 0 0 0 0 SY ? 0 Mar 14 console 0:01 sched
8 S root 1 0 0 41 20 ? 102 ? Mar 14 console 3:31 /etc/init -
19 S root 2 0 0 0 SY ? 0 ? Mar 14 console 0:00 pageout
19 S root 3 0 1 0 SY ? 0 ? Mar 14 console 287:46 fsflush
# 2  
Old 04-09-2005
Do you want to check if a particular process is running? If yes, then you can directly run:

Code:
ps -ef |grep "process_name" > /dev/null 2>&1
echo $?

If the output of echo is 0, then the process is running, else if it is 1, then the process is not running.

Then you can take the appropriate action as per your requirements.
# 3  
Old 04-09-2005
If you are just looking for the return, I'd use 'pgrep' instead of piping ps to grep. You can still use blowtorch's suggestion to check the return, but it is a little more efficent and will always ignore the calling process as shown below:

$ time pgrep ttymon
355
8328

real 0m0.03s
user 0m0.00s
sys 0m0.03s
$ time ps -ef | grep ttymon
root 355 345 0 Feb 14 ? 0:00 /usr/lib/saf/ttymon
root 8328 1 0 Feb 15 console 0:00 /usr/lib/saf/ttymon -g -h -p tweety console login: -T sun -d /dev/console -l c
kduffin 11767 11458 0 08:55:24 pts/12 0:00 grep ttymon

real 0m0.12s
user 0m0.07s
sys 0m0.05s

Cheers,

Keith
# 4  
Old 04-11-2005
guys,
Thanks for you intrest in helping me, but what i'm looking is to notify me all the system as well as user processes that have stopped on that perticular system. so that we can restart and get my work going.
we have some application , webserver which stops working cause the http or db services get aborted or stoped unknowingly. this stoped or aborted process have to be notified.
Kindly let me know if my query is clear or not.

Regards,
Pradeep Kulkarni
# 5  
Old 04-11-2005
Thats what we are helping you with.

As Keith says, you can use pgrep (or grep) to check if a particular process is running or not. I will give you an example.

To check if the webserver is up or not - check for daemon httpd.

Code:
ps -ef | grep httpd | grep -v grep
if [ $? -ne 0 ]; then
    <do your notification stuff here - mail or whatever>
fi

Is this clearer? In this way, you can check for whatever processes that are required to be running. Also, you can put this in cron so that this will run say every 5 min (or whatever interval that you want).

Cheers
# 6  
Old 04-11-2005
Hello blowtorch,
I agree with you and thanks for you reply, but one problem that i have is, i have such mamy process and for that i need to write this piece of code for each and every process, which does not sound good. hence i was trying to find some simpler way where i get information about all stoped processes and not grep for a perticular process. as i need to use this script in the cron.

can you help me on this.

Thanks
pradeep
# 7  
Old 04-11-2005
There is no way really that you could check for a process that is no longer running. The best (and only?) way is to check if a process is running and act if it is not.

I have a suggestion for you. Make a list of all processes that you want running. i.e httpd, sshd, inetd, whatever.. and put them in a file; say proc_check.txt and store it in a secure directory such as /root.

Use the following code in a script that will execute from root crontab.
Code:
while read proc_name; do
   ps -ef | grep $proc_name | grep -v grep > /dev/null 2>&1
   if [ $? -ne 0 ] ; then
      <do the notification stuff here>
   fi
done < /root/proc_check.txt


Even if you have a very large number of processes to check for, the list creation will be a one time job. And you can always add/delete processes from the list as per your requirements.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on filtering

Hi experts, I have a file image.csv as below: COMPUTERNAME,23/07/2013,22/07/2013,21/07/2013,20/07/2013,19/07/2013,18/07/2013,17/07/2013 AED03852180,3,3,3,3,3,3,3 AED03852181,3,3,3,3,3,3,1 AED09020382,3,0,3,0,3,3,3 AED09020383,1,3,3,3,2,1,3 AED09020386,3,3,0,3,3,0,3 ... (4 Replies)
Discussion started by: zaq1xsw2
4 Replies

2. UNIX for Dummies Questions & Answers

filtering out certain output

hi guys, i have a long output and cant figure out a flexible way to show the meta members from a device. please help. some device have 2,4 or 8 meta members but for this example i have 4 meta members, what is a flexible way to pull them out from this output? need your inputs thanks. ... (4 Replies)
Discussion started by: prodigy06
4 Replies

3. UNIX for Dummies Questions & Answers

Filtering the duplicates

Hello, I want to filter all the duplicates of a record to one place. Sample input and output will give you better idea. I am new to unix. Can some one help me on this? Input: 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr1.fa chr1.fa... (2 Replies)
Discussion started by: koneru_18
2 Replies

4. Shell Programming and Scripting

Filtering

Hi I am interested in DNS resolving a set of sites and each time the output is different- $ host www.yahoo.com www.yahoo.com is an alias for fd-fp3.wg1.b.yahoo.com. fd-fp3.wg1.b.yahoo.com is an alias for ds-fp3.wg1.b.yahoo.com. ds-fp3.wg1.b.yahoo.com is an alias for... (1 Reply)
Discussion started by: jamie_123
1 Replies

5. AIX

Need help with filtering

Hi!! I have a bit of a task here and filtering/scripting not my strongest. I have to collect info of approx 1100 hdiskpower.so i have appended all the hdisk into a text file and i need it to run the command lscfg -vl to confirm if the drive is symmetrix. here's what i have so far at... (3 Replies)
Discussion started by: vpundit
3 Replies

6. Shell Programming and Scripting

filtering string

hlow all i need help for my case i want to get variable 20(in bold) but filter in print $3 not $2 so this input 95:20111005_20111123:1821546322 96:20111005_20111123:0053152068 97:20111005_20111123:1820960407 98:20111005_20111123:2021153102 99:20111005_20111123:2021153202... (4 Replies)
Discussion started by: zvtral
4 Replies

7. Shell Programming and Scripting

filtering with awk

i have question about awk ex: input.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 msn,1252468812,8.9 1252468923,gmail,12 live,1252468812,3.4 yahoo,1252468812,9.0 1252468929,msn,1.2 output.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 msn,1252468812,8.9... (3 Replies)
Discussion started by: zvtral
3 Replies

8. Shell Programming and Scripting

Please help me to do some filtering

I have to grep a pattern. scenario is like :- Suppose "/etc/sec/one" is a string, i need to check if this string contains "one" using any utility something like if /etc/sec/one | grep ; then Thanks in advance Renjesh Raju (3 Replies)
Discussion started by: Renjesh
3 Replies

9. UNIX for Dummies Questions & Answers

Filtering exact process name from ps

Hi Gurus, I have two processes running on a Unix box, named say, PRCS1 and PRCS1X. I want to check whether process PRCS1 is running or not, and depending on that I have to make further decisions while writing a shell script. I am using: ps -eaf|grep PRCS1|grep -v grep But the... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

10. UNIX for Advanced & Expert Users

awk filtering ?

I have a Ques. Regarding awk I have few strings in a file, like.. ABC DEF_ABC GHI_ABC GHI Now I want string which has only 'ABC', not the part of any other string as it is also present in 'DEF_ABC' Output should be ABC Please guide me asap !! Thanks :b: (4 Replies)
Discussion started by: varungupta
4 Replies
Login or Register to Ask a Question