The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help in wrting Load Script for a Load-Resume type of load. ankitgupta Shell Programming and Scripting 1 11-09-2006 09:46 PM
Library won't load sansan UNIX for Dummies Questions & Answers 0 11-06-2006 01:42 AM
could not load hme nikk UNIX for Advanced & Expert Users 1 12-20-2004 09:12 PM
NFS Load malcom UNIX for Advanced & Expert Users 1 06-03-2004 07:39 AM
when i try to load Redhat 7.2 ASpin Filesystems, Disks and Memory 2 11-13-2002 03:36 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
How to find the load on CPU ?

Hi ALL,
I have to develop a script which checks for the load on CPU on regular intervals. I created a simple script which uses 'uptime' command to find out the avg load in the last 5 min. I then used grep and put the value of the avg load in a variable OUT.

It was working fine till now. Now I have to build one more condition wherein if the load is above 5 then I have to find out the top processes which are consuming the resources. I tried the following

if [ "$OUT" -gt "$THRESHOLD" ]
then
top -n 1 > top$$.lst
fi

But this is not working since OUT is a character variable and if condition is expecting it to be integer.

Please help me out.
Reply With Quote
Forum Sponsor
  #2  
Old 08-29-2008
Registered User
 

Join Date: Aug 2008
Location: India
Posts: 108
OUT=`uptime|cut -d"," -f6|cut -d"." -f1`
THRESHOLD="5"
if [ "$OUT" -gt "$THRESHOLD" ]
then
echo "Below are the TOP 5 processes"
ps -eo pcpu,pid,user,args | sort -r|grep -v "%CPU"|head -5
else
echo "CPU under control"
fi
Reply With Quote
  #3  
Old 08-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
Thanks for your reply.

But the problem is not solved. Here is the script ....

#!/bin/ksh

OUT1=`date | awk '{print $1" "$2" "$3" "$4" "}'`
TIME=`date +%H:%M`
OUT2=`uptime | awk '{print $8}' | sed 's/\,//g'`
OUT=`uptime|cut -d"," -f6|cut -d"." -f1`
echo $OUT2
THRESHOLD="5"
if [ "$OUT" -gt "$THRESHOLD" ]
then
top -n 1 > top$TIME
fi


and when I run it following it errors out with following :

-bash: [: : integer expression expected

Any Clues ??
Reply With Quote
  #4  
Old 10-04-2008
Banned
 

Join Date: Aug 2008
Posts: 9
if ur using the bash shell change ksh to bash...
Reply With Quote
  #5  
Old 10-05-2008
Registered User
 

Join Date: Jul 2008
Posts: 4
I did the change ... but it didnt help ...
Reply With Quote
  #6  
Old 10-13-2008
Registered User
 

Join Date: Sep 2008
Posts: 2
have u been try this?
if [ "$OUT" > "$THRESHOLD" ]
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0