The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Diff b/n kill and kill -9 ammu UNIX for Advanced & Expert Users 2 07-18-2007 06:29 PM
kill(0,-9) don't kill the process umen High Level Programming 9 06-19-2007 07:09 AM
not able to kill find with kill -9 Amardeep UNIX for Dummies Questions & Answers 5 01-04-2007 05:49 PM
KILL PID, intern should kill another PID. rkrgarlapati Shell Programming and Scripting 4 10-17-2006 08:47 AM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 05:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2006
sparcguy sparcguy is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Posts: 316
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 (permalink)  
Old 11-27-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
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 (permalink)  
Old 11-27-2006
sparcguy sparcguy is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Posts: 316
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0