Need suggestion about grep and CPU usage


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need suggestion about grep and CPU usage
# 1  
Old 01-14-2010
Need suggestion about grep and CPU usage

guys i need suggestion about how to grep cpu usage and then compare it
example :
if cpu usage <= 40% then print normal and how much cpu usage is
or cpu usage between 40%-65% print normal and much cpu usage is

i've tried like this one but got error

Code:
DOMAIN=`uname -n`
cpuload="/users/daniel/cpuload.txt"
usage=`top $DOMAIN | grep idle` >> $cpuload`
usage2=`$cpuload | awk '{print $3}'`
for DOMAIN in ${usage};
do 
 $usage2
 {  
   if[$usage2 <= 40%]; then 
    echo "$DOMAIN Normal $usage2"
   elif [$usage2 -ge 40% && $usage2 -lt 65%] 
    then echo "$DOMAIN Warning $usage2"      
   elif$usage2 -ge 65% && $usage -lt 70%
    then echo "$DOMAIN Major $usage2"
   else         
    echo "$DOMAIN Critical $usage2"   
   fi
 } 
done


thanks before

Last edited by pludi; 01-14-2010 at 06:05 AM.. Reason: code tags, please...
# 2  
Old 01-14-2010
Code:
elif$usage2 -ge 65 && $usage -lt 70

Should read:
Code:
elif [ $usage2 -ge 65 && $usage -lt 70 ]

Likewise other percentages need the % sign stripped off them, compare the integers only.

e.g.:
Code:
VARNUM=60
if [ $VARNUM -le 50% ]; then
  echo less than
elif [ $VARNUM -gt 75% ] ; then 
  echo greater than
else 
  echo in between
fi
bash: [: 50%: integer expression expected
bash: [: 75%: integer expression expected

versus:

Code:
VARNUM=60
if [ $VARNUM -le 50 ]; then
  echo less than
elif [ $VARNUM -gt 75 ] ; then
  echo greater than
else
  echo in between
fi
in between
#
VARNUM=90
if [ $VARNUM -le 50 ]; then
  echo less than
elif [ $VARNUM -gt 75 ] ; then
  echo greater than
else
 echo in between
fi
greater than
#
VARNUM=40
if [ $VARNUM -le 50 ]; then
  echo less than
elif [ $VARNUM -gt 75 ] ; then
  echo greater than
else
  echo in between
fi
less than

# 3  
Old 01-14-2010
since cpu usage use decimal number
can i compare it??
exp:
Code:
usage=`top | grep idle | cut -b 13-17'
if [$usage -lt 45 ] then
   echo"temp $usage"
fi

can i use code like that???

thanks
# 4  
Old 01-15-2010
The tests -eq, -gt and -lt are for comparing integers only.
# 5  
Old 01-17-2010
Quote:
Originally Posted by TonyFullerMalv
The tests -eq, -gt and -lt are for comparing integers only.
so how to compare integer with decimal???
# 6  
Old 01-17-2010
Quote:
Originally Posted by ashary
so how to compare integer with decimal???
One simple way is to use a shell that support it, like ksh93:

Code:
$ bash
$ a=3.5
$ b=2.3
$ if [ $a -gt $b ]
> then
>  echo $a is greater than $b
> fi
bash: [: 3.5: integer expression expected
$ ksh93
$ a=3.5
$ b=2.3
$ if [ $a -gt $b ]
> then
>  echo $a is greater than $b
> fi
3.5 is greater than 2.3
$

# 7  
Old 01-18-2010
Why not use prstat -a it uses less resources compared to top.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Top 5 cpu and Mem consuming process and files and suggestion for health check

I am middle of writing health check scripts, can you pls share commands on how I can get cpu and Mem of top consuming process info at the moment? Also can u suggest ideas on what all I can look for as a part do health check on red hat Linux server? I searched on site before posting, but... (2 Replies)
Discussion started by: Varja
2 Replies

2. UNIX Desktop Questions & Answers

Tool suggestion for collection CPU/memory Stats

Hi, We have around 1000 server (Red Hat + Suse + Parallels + Solaris-9/10/11). Every month, we generate a report for all servers for CPU and Memory utilization in 'percentage used'. This report is generated from HP Openview and frequency is every file minutes. In HP OpenView, we are picking 20... (0 Replies)
Discussion started by: solaris_1977
0 Replies

3. UNIX for Dummies Questions & Answers

CPU usage

well i want to get the cpu usage of the current processes.the thing is that i want to list the processes with cpu usage=0 and the others(one list for cpu usage=0 and another for cpu usage>0)..i can list them,but i cant find a way to find the ps with cpu usage=0 and cpu usage>0..pls help me with... (6 Replies)
Discussion started by: strawhatluffy
6 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. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

6. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

7. 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

8. Programming

CPU usage and memory usage

Please tell me solaris functions/api for getting following information 1- Function that tells how much memory used by current process 2- Function that tells how much memory used by all running processes 3- Function that tells how much CPU is used by current process 4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

9. UNIX for Dummies Questions & Answers

grep Vs CPU usage

Hi, I have one basic doubt, that using grep command frequently , will it have direct impact on the CPU load, pls clarify for eg, if i run a non stop script containing while loop to grep some parameters, what will be the load in CPU.. thanks (3 Replies)
Discussion started by: vasikaran
3 Replies

10. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
Login or Register to Ask a Question