How to find the load on CPU ?


 
Thread Tools Search this Thread
Operating Systems Linux How to find the load on CPU ?
# 1  
Old 08-29-2008
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.
# 2  
Old 08-29-2008
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
# 3  
Old 08-29-2008
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 ??
# 4  
Old 10-05-2008
if ur using the bash shell change ksh to bash...
# 5  
Old 10-05-2008
I did the change ... but it didnt help ...
# 6  
Old 10-13-2008
have u been try this?
if [ "$OUT" > "$THRESHOLD" ]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CPU load in video decoding using SAR

Hi, I'm John_giova and I'm new in this Forum. Sorry my english, it's not my first language. So, I'm trying to check the CPU utlization during the video encoding and decoding (making a comparison between SW and HW ) using the SAR tool. According to a past thread I saw as CPU utilization I should... (4 Replies)
Discussion started by: John_giova
4 Replies

2. Shell Programming and Scripting

Monitor the CPU load for each process and total

Hi guys, I have to set up a script which monitors the amount of AVG CPU load per each process and also the total load for a sum of processes. The processes have the same name, I can only differentiate by port number they listen to, as follows : 28171 root 20 0 1089m 21m 3608 S 103... (1 Reply)
Discussion started by: liviusbr
1 Replies

3. Shell Programming and Scripting

how to increase cpu load

can someone suggest me some code in any language that will increase CPU and memory both. (3 Replies)
Discussion started by: learnbash
3 Replies

4. AIX

CPU Load balancing in AIX 5.2, Oracle

I am neither a DBA nor an AIX spcialist. We are running Oralce 11G on P5, AIX5.3. Per Oracle reports we are using 16 CPUs and 8 cores. However when I am looking at nmon report I find the cpu utilization is not load balanced. CPU_SUMM User% Sys% Wait% Idle% xxx001 74.2 23.6 1.0 1.3 xxx002 ... (4 Replies)
Discussion started by: ucbus
4 Replies

5. Shell Programming and Scripting

System Health - Cpu, Load, IO Monitor

hello there, can someone please tell me the commands that makes sense, from a production point of view, to be used to make sure CPU, LOAD or IO usages on a Linux or Solaris server isn't too high? I'm aware of vmstat, iostat, sar. But i seriously need real world advice as to what fields in... (1 Reply)
Discussion started by: SkySmart
1 Replies

6. Shell Programming and Scripting

awk & CPU Load

Deal All, I'm writing a simple awk to generate some sort of report. The awk will check 24 files (file generated each one hour in a wholoe day) and then it will print one field to another file for counting purposes. The script is working fine but the problem is that the CPU load is very high... (10 Replies)
Discussion started by: charbel
10 Replies

7. Solaris

CPU load -12.50 in server.

Friends I have noticed that the Sun Fire v490 server with Solaris9 OS in my office, is showing a load of 12.50 during peak time and the CPU showing a max of 75% and an average of 60%. The Application running in this machine hung last month(For reasons unknown) and is running fine after... (5 Replies)
Discussion started by: Renjesh
5 Replies

8. Red Hat

High cpu load average

Hi Buddies, Thanx for reading my first post... After googling a lot and searching so many forums I am feeling down a bit... Please don't mind my ignorence, and my grammer ... :) My server is running RHEL 2.6.9-5.EL. The cpu load is going higher than roof, almost 100 sometimes. I am... (2 Replies)
Discussion started by: squid04
2 Replies

9. AIX

Application high CPU load

after a long period of running, the network application's CPU load in our syst em increase slowly, the failed at the end. we use "truss" tool to trace the process, found that it processes something like "semop" ,"semctl","thread_waitlock","kread" kernel call . The trace log file looks like the... (0 Replies)
Discussion started by: Frank2004
0 Replies

10. UNIX for Dummies Questions & Answers

CPU load unit of measure?

If unix says my cpu load is 2.15 exactly what does that mean? --Jason (1 Reply)
Discussion started by: Mac J
1 Replies
Login or Register to Ask a Question