awk, grep and kill


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, grep and kill
# 1  
Old 11-27-2006
awk, grep and kill

Hi there folks,

I'm newbie here and need some help from the gurus in this forum, pls excuse me as my english is not very good.


WARNING long post!!

I have a simple script running on my box which basically polls every 5mins to check the utilization of certain iplanet SOP application processes, if the process exceed > 80% it gets killed and the application will automatically respawn a new process but running at lower cpu.

while true
do
rm -f /tmp/HIGH_SOP_CPU.*
ps -edf -o user,pcpu,pid | grep -i sopias | awk '$2 > 80.0 { print }' >> /tmp/HIGH_SOP_CPU.`date +%d%m%y%H%M`
if (test -s /tmp/HIGH_SOP_CPU.`date +%d%m%y%H%M`) then
kill -9 `ps -edf -o user,pcpu,pid | grep -i sopias | awk '$2 > 80.0 { print $3 }
'`
fi
sleep 300
done


However the problem is this script only checks for a single process > 80%, if there are more than 1 or a few sopias process running concurrently and all of them under 80% utilization but collectively contribute to taking > 80% of system cpu resources it goes undetected by the script until the users complain then it needs to be killed manually.

I'm trying to either expand the current script or write a seperate one which greps all the sopias processes, find the total utilization and if > 80%, find the largest utilized process and kill it. Of course it's easier said than done and I'm still trying to find out how to do it.

I'm trying to find out how I can couple these 2 awk statements together without using flatfiles.

awk '{for (i=1; i<=NF; i++) s=s+$i}; END {print s}'` `ps -edf -o user,pcpu,pid | grep -i sopias | awk '{ print $2}'`

basically the ps statement greps a list of all the utilization and pipes to the for-loop which does the calculations, if I use a flatfile for the `ps` it works fine.

any ideas how not to do it with a flatfile? And maybe a sample awk script that can show me how to find the largest number from a range of numbers.

thx in advance

Last edited by sparcguy; 11-27-2006 at 04:33 AM..
# 2  
Old 11-27-2006
use the following logic in your scripts

Code:
df -k |grep %|grep -v "/proc"|grep -v "/stats"|grep -v "/dev/fd"|sed -e 's/%//'|awk '{ print $6 " " $5 }' > /tmp/tmpfile
cat /tmp/tmpfile | while read dsk usg
do
        if [ $usg -gt 99 ]
        then
                echo "$dsk partition is $usg% full" >> $FILETMP2
        fi
done

what would i suggest you , redirect the result of the command to variable
then use it.

Brds
# 3  
Old 11-27-2006
hi thx for your reply.

my original post refers to finding a way to kill certain processes taking too much cpu resources not disk resources.

thks anyway
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to kill a process

Hi Guys I am running a small script to find a process id , ask user if they want to kill the process and then action it Yes or no Here is what i have #/bin/bash ps -l | grep -i $1 | awk '{print "Process id of '$1' is "$4""}' echo "Do you want to kill this process (Y/N)" read action... (10 Replies)
Discussion started by: johnnybananas
10 Replies

2. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

3. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

4. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 12.4 1.72849432773174e+01 -7.74784188610632e+01 12.5 9.59432114416327e-01 -7.87018212757537e+01 15.6 5.20139995965960e-01 -5.61612429666624e+01 29.3 3.76696387248366e+00 -7.42896194101892e+01 32.1 1.86899877018077e+01 -7.56508762501408e+01 35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies

5. Shell Programming and Scripting

kill a process if grep match is found

Hi, I need something unusual, I guess. I need to start a process, and if that process displays a specific error message, I need to kill that process and restart it. Something like: startprocess | grep -i "This is the specific error message" && kill $pidof(startprocess) Explanation, I need... (4 Replies)
Discussion started by: burek
4 Replies

6. Shell Programming and Scripting

pass an awk variable to kill

Does anyone know of a way to do something similar to this with awk and kill? I want to create the variable in awk and pass that variable to kill. ps -ef | grep -i chromium | awk '{$2=x}' | kill -9 $x 2>/dev/null (9 Replies)
Discussion started by: cokedude
9 Replies

7. UNIX for Dummies Questions & Answers

Send output of grep as input of kill command

I would appreciate any help. I need to run 'ps -ef | grep 'process', get the process id and kill that process. I have got this far: - Get pid using ps -ef | awk '/process/{ print $2}' after this I'm kind of stuck.. - Use pipe to redirect the output to kill pid=ps -ef | awk '/bmserver/{... (2 Replies)
Discussion started by: foxtron
2 Replies

8. Shell Programming and Scripting

Kill a process from a grep

Soz im a bit newbie... I want to do: ps -A | grep firefox | kill $1 it should kill the pid associated, but it doesnt work. $1 is the pid (if i do a awk {'print $1'} i get it ) , but kill doesnt take it as such... How can i do it? (3 Replies)
Discussion started by: ierpe
3 Replies

9. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

10. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies
Login or Register to Ask a Question